【问题标题】:how to use StreamingReader with asset files , getting java.lang.NoClassDefFoundError: Failed resolution of: [Ljava/nio/file/attribute/FileAttribute;如何将 StreamingReader 与资产文件一起使用,获取 java.lang.NoClassDefFoundError: Failed resolution of: [Ljava/nio/file/attribute/FileAttribute;
【发布时间】: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 以打开多索引。没用

【问题讨论】:

    标签: java android


    【解决方案1】:

    这可能是因为您没有启用多索引。您需要将以下依赖项添加到您的 gradle。

    implementation 'com.android.support:multidex:1.0.3'

    并在 defaultConfig 中设置 multiDexEnabled true 以打开多索引。

    【讨论】:

    • 问题依然存在
    • 如果它可能有帮助:原因:java.lang.ClassNotFoundException:在路径上找不到类“java.nio.file.attribute.FileAttribute”:DexPathList [[zip file“/data/ app/com.example.djsde.splashactivity-2/base.apk”,压缩文件......
    猜你喜欢
    • 2018-11-19
    • 1970-01-01
    • 2019-08-23
    • 2022-11-11
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多