#StackBounty: #java #android #apache-poi #docx Getting the lines of each paragraphs of a docx with Apache-POI

Bounty: 300

I am using the library Apache-POI for my app. Specifically, POIshadow-all (ver. 3.17) for reading a Word document.
I am successfully extracting every paragraph as follows:

enter image description here

what I actually need is extract every line, as follows:

enter image description here

The code to extract every paragraph is this:

 try {

            val fis = FileInputStream(path.path + "/" + document)
            val xdoc = XWPFDocument(OPCPackage.open(fis))

            val paragraphList: MutableList<XWPFParagraph> = xdoc.paragraphs

            private val newParagraph = paragraph.createRun()


            for (par in paragraphList) {

                    var currentParagraph = par.text
                    Log.i("TAG","current: $currentParagraph")


The variable currentParagraph returns a whole paragraph, as expected. However, I would need a variable named currentLine which returns a single line.

I’ve research about this issue in stackoverflow and other sites. I’ve found some proposals but none of them works for me.
I also tried get dates by ctr and using XWPFRun, without any success.

I would be grateful for any recommendation on how to proceed.

Thanks in advance for your help.

Get this bounty!!!

#StackBounty: #android #kotlin #apache-poi #build.gradle Android Apache POI error when reading Word document: org.apache.xmlbeans.Schem…

Bounty: 400

I am trying to use Apache POI in my Android application so that I can read word files. I am integrating the POIA library which enables Apache POI usage on Android (https://github.com/SUPERCILEX/poi-android). However, when I run my code and read in a Word file, I receive the following error:

Exception: org.apache.xmlbeans.SchemaTypeLoaderException: Cannot
resolve type for handle _XY_Q=space|R=space

Below is my code (I am receiving error on the first line):

var document = XWPFDocument(uri?.let { contentResolver.openInputStream(it) });
var extractor = XWPFWordExtractor(document);
var documentText = extractor.text; // Retrieve the document's text

At runtime I have the following code:

System.setProperty("org.apache.poi.javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl")
System.setProperty("org.apache.poi.javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl")
System.setProperty("org.apache.poi.javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl")

Below is my gradle (project-level):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.60'
    repositories {

    ext {
        poiVersion = '3.17'
    dependencies {
        classpath 'com.android.tools:r8:1.4.93'
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }

task clean(type: Delete) {
    delete rootProject.buildDir

Below is my gradle (app-level):

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.diffchecker"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    // For developers using the Android Support Library
    implementation 'pub.devrel:easypermissions:2.0.1'
    implementation 'com.google.android.gms:play-services-ads:18.3.0'
    implementation ("com.github.SUPERCILEX.poi-android:poi:$poiVersion") {
        exclude group: 'stax', module: 'stax-api'

Below is the full stack trace:

I/System.out: Exception: org.apache.xmlbeans.SchemaTypeLoaderException: Cannot resolve type for handle _XY_Q=space|R=space@http://www.w3.org/XML/1998/namespace (schemaorg_apache_xmlbeans.system.sF1327CCA741569E70F9CA8C9AF9B44B2.cttext7f5btype) - code 13

IMPORTANT: I am trying to read in the contents of a Word file the USER SELECTED, not a Word file from a hardcoded path.

Please include ALL the relevant code in your answer.

Get this bounty!!!