本文介绍了错误:java.lang.NoClassDefFoundError:无法解决以下问题:Lorg/apache/xmlbeans/XmlOptions;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图使用​​Apache将数据写入Excel,但在此行中出现错误 XSSFWorkbook workbook = new XSSFWorkbook();我在下面发布了错误日志,请检查.

I am tring to write data into Excel using Apache,i am getting error in this line XSSFWorkbook workbook = new XSSFWorkbook();I posted my error log below please check.

 Process: app.msupply.com.ideaurben, PID: 28508
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/xmlbeans/XmlOptions;
at org.apache.poi.POIXMLDocumentPart.<clinit>(POIXMLDocumentPart.java:53)
at app.msupply.com.ideaurben.Adapter.ReportcateorieslistAdapter$MyViewHolder$2.onResponse(ReportcateorieslistAdapter.java:384)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.xmlbeans.XmlOptions" on path: DexPathList[[zip file "/data/app/app.msupply.com.ideaurben-1/base.apk"],nativeLibraryDirectories=[/data/app/app.msupply.com.ideaurben-1/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:53) 
at app.msupply.com.ideaurben.Adapter.ReportcateorieslistAdapter$MyViewHolder$2.onResponse(ReportcateorieslistAdapter.java:384) 
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68) 
at android.os.Handler.handleCallback(Handler.java:746) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
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)
... 11 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

我的 libs 文件夹:我将所有库添加到libs文件夹中.

my libs folder: i add all the library in libs folder.

我的Java类代码:

    try {

            String FILE_NAME = "/tmp/MyFirstExcel.xlsx";
            XSSFWorkbook workbook = new XSSFWorkbook();

          XSSFSheet sheet = workbook.createSheet("Datatypes in Java");
          Object[][] datatypes = {
                  {"Datatype", "Type", "Size(in bytes)"},
                  {"int", "Primitive", 2},
                  {"float", "Primitive", 4},
                  {"double", "Primitive", 8},
                  {"char", "Primitive", 1},
                  {"String", "Non-Primitive", "No fixed size"}
          };
          int rowNum = 0;
          System.out.println("Creating excel");
          Iterator<org.apache.poi.ss.usermodel.Row> rowIterator = sheet.iterator();
          for (Object[] datatype : datatypes) {
              Row row = sheet.createRow(rowNum++);
              int colNum = 0;
              for (Object field : datatype) {
                  Cell cell = row.createCell(colNum++);
                  if (field instanceof String) {
                      cell.setCellValue((String) field);
                  } else if (field instanceof Integer) {
                      cell.setCellValue((Integer) field);
                  }
              }
          }
          FileOutputStream outputStream = new FileOutputStream(FILE_NAME);
          workbook.write(outputStream);
        //  workbook.close();


      } catch (IOException e) {
          e.printStackTrace();
      } /*catch (JSONException e) {
          e.printStackTrace();
      }*//*catch (FileNotFoundException e) {
          e.printStackTrace();
      }*/

  }

Build.gradel 文件如下.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "app.msupply.com.ideaurben"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        dexOptions {
            jumboMode true
        }
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/LGPL2.1'
        }

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support:support-v4:26.+'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
    compile 'com.android.support:cardview-v7:25.2.0'
    testCompile 'junit:junit:4.12'
}

请帮助任何人,谢谢.

推荐答案

我想纠正其他人对NoClassDefFoundError的看法.

I'd like to correct the perspective of others on NoClassDefFoundError.

NoClassDefFoundError可能由于多种原因而发生

NoClassDefFoundError can occur for multiple reasons like

  1. ClassNotFoundException-找不到该引用类的.class,无论它在编译时是否可用(即基类/子类).
  2. 已找到类文件,但在初始化静态变量时引发了异常
  3. 位于类文件中,初始化静态块时引发异常
  1. ClassNotFoundException -- .class not found for that referenced class irrespective of whether it is available at compile time or not(i.e base/child class).
  2. Class file located, but Exception raised while initializing static variables
  3. Class file located, Exception raised while initializing static blocks

说在编译时可用"是什么意思?

What it means by saying "available in compile time"?

  • 代码中使用了引用的类.例如:A和B两类(扩展A).如果直接在代码中引用B,则它在编译时可用,即A a = new B();
  • The referenced class is used in the code.Eg: Two classes, A and B(extends A). If B is referenced directly in the code, it is available at compile time, i.e. A a = new B();

说在编译时不可用"是什么意思?

What it means by saying "not available at compile time"?

  • 编译时间类和运行时类不同,即,例如,使用子类的子类名称加载基类,例如Class.forName("classname")例如:A和B两类(扩展A).代码有

  • The compile time class and runtime class are different, i.e. for example base class is loaded using classname of child class for example Class.forName("classname")Eg: Two classes, A and B(extends A). Code has

A a = Class.forName("B").newInstance();

A a = Class.forName("B").newInstance();

这篇关于错误:java.lang.NoClassDefFoundError:无法解决以下问题:Lorg/apache/xmlbeans/XmlOptions;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 09:00