我知道这个问题在此之前已经被很多人问过了,但是我在大多数帖子中尝试了这个解决方案,但仍然面临着问题。Android POI插件说在APK-META-INF中复制文件
我想读取android应用程序中的excel(xlsx)文件。 我已经下载了POI jar文件并将其添加到lib文件夹,也增加一条,作为依赖 [1.poi-3.7.jar 2.poi-OOXML-3.7.jar]
首先,我得到这个错误: -
Duplicate files copied in APK META-INF/notice.txt
我发现这个链接Click here to view
并通过依赖将此代码添加它解决了这个问题
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'
}
但后来我在运行时
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收到错误 - 这个类抛出上述错误。
代码如下给出: -
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());
,并做一些研究,我发现,当一个文件在编译时被发现,但在运行时没有发现这一错误后抛出。虽然我不确定这一点,但任何人都可以告诉我这里做错了什么。
为什么使用这样一个旧版本的Apache POI?升级时会发生什么? – Gagravarr
ohh对不起@Gagravarr是这个旧版本?我认为这是最新版本。好吧,但它是什么,请给我一些暗示,为什么会得到这个错误。并抱歉迟到回复。 – RKD
如果您前往[Apache POI主页](http://poi.apache.org/)或[下载页面](http://poi.apache.org/download.html),您将看到最新的版本目前是3.15测试版1.请尝试使用该版本,如果您仍然有任何问题,请回报! – Gagravarr