【发布时间】:2019-02-20 08:01:23
【问题描述】:
我正在使用this library 快速读取保存在资产文件夹android 中的xlsx 文件,正如this answer 中所建议的那样
在运行应用程序时出现以下错误
W/System.err: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.djsde.splashactivity, PID: 31903
java.lang.NoClassDefFoundError: Failed resolution of: [Ljava/nio/file/attribute/FileAttribute;
at com.monitorjbl.xlsx.impl.TempFileUtil.writeInputStreamToFile(TempFileUtil.java:11)
at com.monitorjbl.xlsx.impl.StreamingWorkbookReader.init(StreamingWorkbookReader.java:88)
at com.monitorjbl.xlsx.StreamingReader$Builder.open(StreamingReader.java:251)
at com.example.djsde.splashactivity.Puzzle.<init>(Puzzle.java:99)
at com.example.djsde.splashactivity.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6275)
at ...
点击 Puzzle.java:99 后,我会跟随部分代码
InputStream myInput;
try {
AssetFileDescriptor fileDescriptor = assetManager.openFd(xlname);
myInput = fileDescriptor.createInputStream();
Workbook workbook = StreamingReader.builder()
.rowCacheSize(100)
.bufferSize(4096)
.open(myInput); //this line
...
我的 gradle 应用程序文件我已更改如下
apply plugin: 'com.android.application'
android {
...
aaptOptions {
noCompress "xlsx"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/INDEX.LIST'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.monitorjbl:xlsx-streamer:2.1.0'
api group: 'com.fasterxml', name: 'aalto-xml', version: '1.0.0'
}
添加
implementation 'com.android.support:multidex:1.0.3'
并在 defaultConfig 中设置 multiDexEnabled true 以打开多索引。没用
【问题讨论】: