0

I know that this question has been asked by many before this but i have tried the solution in most of the posts but am still facing issue.

I want to read excel(xlsx) file in android app. I have downloaded POI jar files and added it to lib folder and also added it as dependency [ 1.poi-3.7.jar 2.poi-ooxml-3.7.jar ]

First i got this error:-

Duplicate files copied in APK META-INF/notice.txt

I found this link Click here to view

And by adding this code in dependency it solved this issue

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/RELEASE_NOTES.txt';
    exclude 'META-INF/ASL2.0'
}

But then am getting error at runtime

FATAL EXCEPTION: main
    Process: com.pixelmagnus.systemteq, PID: 12872
    java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/xmlbeans/XmlOptions;
    at org.apache.poi.POIXMLDocumentPart.<clinit>(POIXMLDocumentPart.java:44)
    at com.pixelmagnus.systemteq.MainActivity.loadConfiguration(MainActivity.java:68)
    at com.pixelmagnus.systemteq.MainActivity.requestMultiplePermissions(MainActivity.java:55)
    at com.pixelmagnus.systemteq.MainActivity.onCreate(MainActivity.java:35)
    at android.app.Activity.performCreate(Activity.java:6285)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
    at android.app.ActivityThread.access$900(ActivityThread.java:154)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:5526)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.xmlbeans.XmlOptions" on path: DexPathList[[zip file "/data/app/com.pixelmagnus.systemteq-2/base.apk"],nativeLibraryDirectories=[/data/app/com.pixelmagnus.systemteq-2/lib/arm, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    at org.apache.poi.POIXMLDocumentPart.<clinit>(POIXMLDocumentPart.java:44) 
    at com.pixelmagnus.systemteq.MainActivity.loadConfiguration(MainActivity.java:68) 
    at com.pixelmagnus.systemteq.MainActivity.requestMultiplePermissions(MainActivity.java:55) 
    at com.pixelmagnus.systemteq.MainActivity.onCreate(MainActivity.java:35) 
    at android.app.Activity.performCreate(Activity.java:6285) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524) 
    at android.app.ActivityThread.access$900(ActivityThread.java:154) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:224) 
    at android.app.ActivityThread.main(ActivityThread.java:5526) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
    Suppressed: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlOptions
    at java.lang.Class.classForName(Native Method)
    at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
    ... 17 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

XSSFWorkbook -- This class is throwing above error.

Code is give below:-

String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/systemteqconfig";
        String imagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/systemteqconfig/images";
        File headingService = new File(path, "headingservice.xlsx");
        FileInputStream fis = new FileInputStream(headingService);
        XSSFWorkbook work_book = new XSSFWorkbook(fis);
        XSSFSheet sheet = work_book.getSheetAt(0);
        Iterator<Row> row = sheet.rowIterator();
        int i = 0;
        while(row.hasNext()){
            if(i!=0){
                XSSFRow content = (XSSFRow)row.next();
                HashMap<String,String> hm = new HashMap<String,String>();
                hm.put("name",content.getCell(0).getStringCellValue());
                hm.put("english",content.getCell(1).getStringCellValue());
                hm.put("image",imagePath+"/"+content.getCell(2).getStringCellValue());
                hm.put("request",content.getCell(3).getStringCellValue());
                hm.put("response_one",content.getCell(4).getStringCellValue());
                hm.put("response_two",content.getCell(5).getStringCellValue());
                hm.put("active_color",content.getCell(6).getStringCellValue());
                hm.put("dutch",content.getCell(7).getStringCellValue());
                hm.put("french",content.getCell(8).getStringCellValue());
                hm.put("spanish",content.getCell(9).getStringCellValue());
                hm.put("portuguese",content.getCell(10).getStringCellValue());
                hm.put("polish",content.getCell(11).getStringCellValue());
                hm.put("chinese",content.getCell(12).getStringCellValue());
                hm.put("japanese",content.getCell(13).getStringCellValue());
                hm.put("arabic",content.getCell(14).getStringCellValue());
                headingContent.add(hm);
            }
            i++;
        }
        headingServicesController hs = new headingServicesController(this);
        hs.addHeadingServices(headingContent);
        ArrayList<HashMap<String, String>> temp = hs.getHeadingService();
        Log.d("CHECKING",temp.toString());

And after doing some research i found that this error is thrown when a file is found in compile time but not found at runtime. Though am not sure about this can any one tell me what am doing wrong here.

Community
  • 1
  • 1
RKD
  • 405
  • 1
  • 5
  • 16
  • 1
    Why are you using such an old version of Apache POI? What happens when you upgrade? – Gagravarr Apr 29 '16 at 18:22
  • ohh sorry @Gagravarr is this the old version? i thought this is the latest version. Okay but what ever it is, please provide me some hint why am getting this error. and sorry for late reply. – RKD May 03 '16 at 07:14
  • If you head to the [Apache POI homepage](http://poi.apache.org/) or [Download page](http://poi.apache.org/download.html) you'll see that the latest version is currently 3.15 beta 1. Try with that, then report back if you still have any problems! – Gagravarr May 03 '16 at 08:48

1 Answers1

0

Currently Apache POI will not work on Android out of the box due to various problems that you will run into when using the libraries from Apache POI directly. Android is more strict on what it allows as part of the jar-files.

There are two projects that should make it possible to use most of Apache POI on Android:

centic
  • 15,565
  • 9
  • 68
  • 125