NoClassDefFoundError用于Android上的Java库中的代码

时间:2023-01-18 23:39:41

I am experiencing an error quite often among my users. The app crashes during startup. When the MainActivity is supposed to be loaded the VM apparently cannot find the class. I cannot figure out why. The architecture of the app is that there is a common project that both my free and pro version are using. Don't know if it is relevant. See the stack trace below. Any thoughts?

在我的用户中,我经常遇到错误。该应用程序在启动时崩溃。当主活动要加载时,VM显然找不到类。我不知道为什么。这个应用的架构是有一个公共项目,我的免费和专业版本都在使用。不知道是否相关。参见下面的堆栈跟踪。任何想法吗?

java.lang.NoClassDefFoundError: com.android.common.MainActivity
at com.mycompany.myapp.Splash.onCreate(Splash.java:23)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.android.common.MainActivity in loader     dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.android.pro-1.apk]

Edit: Thanks for the comment below, Richard. Now I have changed com.android.Splash to something else. It wasn't the real classname anyway. My bad...!

编辑:谢谢你的评论,Richard。现在我换了com。android。溅到别的东西。它不是真正的类名。我的坏!

24 个解决方案

#1


126  

I had the same issue, I did the following to fix the problem.

我有同样的问题,我做了以下的修复问题。

  1. Go to "Properties" of the project.
  2. 进入项目的“属性”。
  3. Select "Java Build Path"
  4. 选择“Java构建路径”
  5. Select "Order and Export" Tab
  6. 选择“Order and Export”选项卡
  7. You should see the selected project's "src" and "gen" paths and dependencies here.
  8. 您应该在这里看到所选项目的“src”和“gen”路径和依赖项。
  9. The order how they listed were first "src" and then "gen" path
  10. 他们列出的顺序首先是“src”,然后是“gen”路径
  11. I switch them, so that "gen" folder is build before the "src"
  12. 我切换它们,这样“gen”文件夹在“src”之前构建

gen - automated code in project (from dependencies and references)
src - source code in project

项目中的自动化代码(来自依赖和引用)src -项目中的源代码

There was no need to restart the Eclipse. It just started working.

没有必要重新启动Eclipse。它刚刚开始工作。

Honestly I have never tried "Android Tools > Fix Project Properties", sometimes it might be doing the same thing. I do not know, I just did above after seen the error message, thinking something is wrong with the build paths.

老实说,我从来没有尝试过“Android Tools >修复项目属性”,有时它也会做同样的事情。我不知道,我只是在上面看到错误消息后才这么做,认为构建路径有问题。


Edit

编辑


Later on it was not sufficient, I was getting the error again. Then I "checked" all the dependencies listed in that view. Now it works again. So far so good. I will keep this updated if it fails again.

后来这还不够,我又犯了一次错误。然后我“检查”视图中列出的所有依赖项。现在工作了。目前为止一切都很顺利。如果它再次失败,我将保持更新。

FYI: in my last attempt, I tried "Android Tools > Fix Project Properties", but it didn't work out for me.

在我最后一次尝试中,我尝试了“Android Tools > Fix Project Properties”,但是没有成功。

#2


18  

I'm currently using SDK 20.0.3 and none of the previous solutions worked for me.

我目前正在使用SDK 20.0.3,以前的解决方案对我都不起作用。

I was able to get things to work by

我能把东西修好

  • Right clicking the Android project
  • 右击Android项目
  • Then selecting Build Path -> Link Source to bring up the Link Source dialog.
  • 然后选择构建路径—>链接源,打开链接源对话框。
  • Then I specified the 'src' folder of the Java project and gave it a name other than the default of 'src' (e.g. 'src2').
  • 然后,我指定了Java项目的“src”文件夹,并给它起了一个名称,而不是默认的“src”(例如)。“src2”)。
  • You can now right-click -> delete the new 'src2' folder.
  • 现在可以右键单击->删除新的“src2”文件夹。

This brought this created Java class files that were compiled for the Dalvik VM instead of the Java VM when the Android project was built. This allowed the Java class files in the Android Library jar file to go thru dexing when the Android project .apk was created. Now when the app was run the Java project classes were found instead of a Java.lang.NoClassDefFoundError being thrown.

这带来了创建的Java类文件,这些文件是在构建Android项目时为Dalvik VM而不是Java VM编译的。这允许在创建Android项目.apk时,Android库jar文件中的Java类文件通过dexing。现在,当应用程序运行时,找到的是Java项目类,而不是Java.lang。抛出NoClassDefFoundError。

If you want to use a jar file instead of linking the source, then you will need to create a Library Android project. (An Android Project with 'is library' checked in Properties -> Android.) You will then need to either link the source of the Java Project to the Android Library project as described above or copy the source files from the 'src' folder of the Java Project to the 'src' folder of the Android Library project. Build the Android Library project. Then you will be able copy the Android Project jar file that was created into the 'libs' folder of the Android folder because the class files in it were compiled for the Davlik VM instead of the Java VM when the Android project was built. This allows the Java class files in the Android Library jar file to go thru dexing when the Android project .apk is created. Now when the app is run the Java project classes will be found instead of a Java.lang.NoClassDefFoundError being thrown.

如果您想使用jar文件而不是链接源文件,那么您将需要创建一个库Android项目。(一个带有“is库”属性的Android项目——> Android。)然后,您需要将Java项目的源链接到上面描述的Android库项目,或者将源文件从Java项目的“src”文件夹复制到Android库项目的“src”文件夹。构建Android库项目。然后,您就可以将Android项目jar文件复制到Android文件夹的“libs”文件夹中,因为其中的类文件是在构建Android项目时为Davlik VM而不是Java VM编译的。这允许在创建Android项目.apk时,Android库jar文件中的Java类文件通过dexing。现在,当应用程序运行时,将找到Java项目类,而不是Java.lang。抛出NoClassDefFoundError。

#3


17  

Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using. i got the solution by following below link NoClassDefFoundError Android Project?

尝试进入项目->属性-> Java构建路径->订单和导出,并确保Android私有库为您的项目和您正在使用的所有其他库项目检查。我通过以下链接NoClassDefFoundError Android项目得到了解决方案?

#4


8  

Just in case it helps someone, I faced the same issue. My jar file was under the libs directory and the jar was added to the build path. Still it was throwing that exception.

为了防止它对某人有所帮助,我遇到了同样的问题。我的jar文件在libs目录下,jar被添加到构建路径中。它仍然抛出了这个例外。

I just cleaned the project and it worked for me.

我刚刚清理了这个项目,它对我起了作用。

Eclipse -> Project -> Clean -> Select the project and clean

Eclipse ->项目-> Clean ->选择项目并Clean

#5


7  

I tried all of the above said solutions but did not worked out for me, Here is what i did to get it done project-> config build path-> order and export-> move dependent project on top

我尝试了以上所有的解决方案,但并没有为我解决,这里是我所做的项目->配置构建路径->订单和export->在上面的依赖项目。

#6


6  

This error is also generated when you make an app that uses the Google API (such as Maps) but run it on a device that targets the Android API.

当您创建的应用程序使用谷歌API(如Maps),但在针对Android API的设备上运行时,也会产生此错误。

#7


5  

I encountered this NoClassDefFoundError when I used java.nio.charset.StandardCharsets.

我在使用java.nio.charset.StandardCharsets时遇到了这个NoClassDefFoundError。

The reason is that StandardCharsets has not existed until JRE 1.7. If I make the java compile version set to 1.7, Eclipse complained that "Android requires compiler compliance level 5.0 or 6.0". So, I fixed it by right-click the project name->Android Tools->Fix Project Properties. It is compiled with JRE1.6.

原因是标准字符集直到JRE 1.7才存在。如果我将java编译版本设置为1.7,Eclipse会抱怨说“Android要求编译器遵循5.0或6.0级”。因此,我通过右键单击项目名称>Android Tools->Fix项目属性来修复它。它是用JRE1.6编译的。

However, because StandardCharsets has not existed until 1.7. It reported NoClassDefFoundError when I ran it.

但是,因为标准字符集直到1.7才存在。当我运行它时,它报告了NoClassDefFoundError。

I has not come to realize this until after trying a lot of other methods including reinstalling JDK. The real reason is clearly told by the meaning of NoClassDefFoundError: The class cannot be found at run time although it passed compilation.

在尝试了许多其他方法,包括重新安装JDK之后,我才意识到这一点。NoClassDefFoundError的意思清楚地说明了真正的原因:类虽然通过编译,但在运行时却无法找到。

General conclusion is that as long as Android does not work with JRE 1.7, if you use any new feature provided since 1.7, you will encounter this error.

一般的结论是,只要Android不支持JRE 1.7,如果使用自1.7以来提供的任何新特性,就会遇到这个错误。

My solution is that I copied those source code into my code!

我的解决方案是将这些源代码复制到我的代码中!

#8


4  

The NoClassDefFoundError description is, from the SO tag:

NoClassDefFoundError描述来自SO标记:

The Java Error thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found. The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

如果Java虚拟机或类加载器实例试图装入类的定义(作为普通方法调用的一部分或使用新表达式创建新实例的一部分),并且找不到类的定义,则会抛出Java错误。当当前正在执行的类被编译时,存在搜索类定义,但是不能再找到定义。

Or better:

或更好:

NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time.

Java的NoClassDefFoundError在Java虚拟机无法在运行时找到特定的类时出现,在编译时可用。

from this page. Check it, there are some ways to solve the error. I hope it helps.

从这个页面。检查一下,有一些方法可以解决这个问题。我希望它有帮助。

#9


3  

For me this problem was related to the API that I was using not being deployed. For example, I used a ZSDK_API.jar as a reference.

对我来说,这个问题与我没有部署的API有关。例如,我使用了ZSDK_API。jar作为参考。

To fix the issue I had to right click on the project and select properties. From JAVA BUILD PATH, I had to add the API that was not being deployed. This was weird as the app was throwing MainActivity class not found and in reality the error was caused by the DiscoveryHandler class not being found.

为了解决这个问题,我必须右键单击项目并选择properties。从JAVA构建路径中,我必须添加没有部署的API。这很奇怪,因为应用程序抛出了未找到的MainActivity类,实际上错误是由于未找到DiscoveryHandler类而导致的。

Hopes this helps someone.

希望这可以帮助别人。

#10


3  

In my case, I was trying to add a normal java class (from a normal java project) compiled with jre 1.7 to an android app project compiled with jre 1.7.

在我的例子中,我试图将一个用jre 1.7编译的普通java类(来自普通java项目)添加到一个用jre 1.7编译的android应用程序项目中。

The solution was to recompile that normal java class with jre 1.6 and add references to the android app project (compiled with jre 1.6 also) as usual (in tab order and export be sure to check the class, project, etc).

解决方案是使用jre 1.6重新编译普通java类,并像往常一样添加对android应用程序项目的引用(也使用jre 1.6编译)(按tab顺序导出,确保检查类、项目等)。

The same process, when using an android library to reference external normal java classes.

同样的过程,当使用android库引用外部普通java类时。

Don't know what's wrong with jre 1.7, when compiling normal java classes from a normal java project and try to reference them in android app or android library projects.

不知道jre 1.7有什么问题,当从普通java项目编译普通java类并试图在android应用程序或android库项目中引用它们时。

If you don't use normal java classes (from a normal java project) you don't need to downgrade to jre 1.6.

如果不使用普通java类(来自普通java项目),则不需要降级到jre 1.6。

#11


2  

I met NoClassDefFoundError for a class that exists in my project (not a library class). The class exists but i got NoClassDefFoundError. In my case, the problem was multidex support. The problem and solution is here: Android Multidex and support libraries

我遇到了NoClassDefFoundError,因为在我的项目中存在一个类(而不是一个库类)。这个班存在,但我没有找到。在我的案例中,问题是multidex支持。问题和解决方案在这里:Android Multidex和支持库。

You get this error for Android versions lower than 5.0.

对于低于5.0的Android版本,您会得到这个错误。

#12


1  

Other idea. For example, you have class derived from "android.support.v4.app.Fragment".

其他的想法。例如,类派生自“android.support.v4.app.Fragment”。

However you made a mistake and inherited it from "android.app.Fragment". Then you will have this error on the Android 2 devices.

然而,您犯了一个错误,并从“android.app.Fragment”继承了这个错误。然后在Android 2设备上就会出现这个错误。

#13


1  

I have just figured out something with this error.

我刚刚算出了这个误差。

Just make sure that the library jar file contains the compiled R class under android.support.v7.appcompat package and copy all the res in the v7 appcompat support "project" in your ANDROID_SDK_HOME/extras/android/support/v7/appcompat folder.

确保库jar文件包含android.support.v7下编译好的R类。appcompat包并复制v7 appcompat支持“项目”中的所有res在您的ANDROID_SDK_HOME/extras/android/support/v7/appcompat文件夹中。

I use Netbeans with the Android plugin and this solved my issue.

我使用Netbeans和Android插件,这解决了我的问题。

#14


1  

I am guessing that you don't specify javac's target when creating the common library, so javac automatically uses the latest available target, which is likely 1.7 (Java7) or 1.8 (Java8).

我猜您在创建公共库时没有指定javac的目标,因此javac会自动使用最新的可用目标,可能是1.7 (Java7)或1.8 (Java8)。

It has already been stated that

已经说过了

Android requires compiler compliance level 5.0 or 6.0

Android要求编译器遵循5.0或6.0级

dx of Android's build tools < 19.0.0 isn't able to convert Java7 (or higher) bytecode to Dalvik bytecode.

dx的Android构建工具< 19.0.0不能将Java7(或更高)字节码转换为Dalvik字节码。

So either use a build tools version >= 19.0.0 or use javac with -target 6, by modifying for example your ant build.xml like this:

因此,要么使用构建工具版本的>= 19.0.0,要么使用带有-target 6的javac,通过修改ant构建示例。xml是这样的:

<javac
srcdir="src/"
destdir="build/"
target="6"
/>

#15


1  

On Android Studio:

在Android上工作室:

1) Add multiDexEnabled = true in your default Config

1)在默认配置中添加multiDexEnabled = true

2) Add compile com.android.support:multidex:1.0.0 in your dependencies

2)添加编译com.android.support:multidex:1.0.0

3) Application class extend MultiDexApplication instead of just Application

应用程序类扩展MultiDexApplication,而不仅仅是Application

#16


0  

I fixed this issue by adding library project path in project.propertied manually. some how eclipse did not added this entry automaticvally along with "add project". so the point where app was trying to refer any componenrt inside lib project it was crashing .

我通过在project中添加library project path解决了这个问题。手动产。一些eclipse没有在“添加项目”的同时自动添加这个条目的方法。所以当app试图在lib项目中引用任何组件时它崩溃了。

you also can try the same thing . app dependecy in projec.properties like

你也可以尝试同样的事情。应用在projec dependecy。属性如

android.library.reference.1=....\android-sdks\extras\google\google_play_services\libproject/google-play-services_lib

android.library.reference.1 = ....谷歌\ android-sdks \配件\ \ google_play_services \ libproject / google-play-services_lib

and run .

和运行。

#17


0  

jars used to be in the lib/ folder, now they're in libs/ If you use lib, you can move your jars from lib to libs, and remove the dependencies from project properties/java build path because Android will now find them automatically.

jar过去在lib/文件夹中,现在在libs/如果您使用lib,您可以将jar从lib移动到libs,并从项目属性/java构建路径中删除依赖项,因为Android现在将自动找到它们。

#18


0  

For me, the issue was that the referenced library was built using java 7. I solved this by rebuilding using the 1.6 JDK.

对我来说,问题是引用的库是使用java 7构建的。通过使用1.6 JDK,我解决了这个问题。

#19


0  

Some time java.lang.NoClassDefFoundError: error appear when use ART instead of Dalvik runtime. To change runtime just go to Developer Option -> Select Runtime -> Dalvik.

一些时间. lang。NoClassDefFoundError:当使用ART而不是Dalvik运行时,会出现错误。要更改运行时,只需切换到Developer选项->选择运行时-> Dalvik。

#20


0  

If none of the above works (like it happened to me), and you're using as a library another project in Eclipse.

如果上面的任何一个都不起作用(就像我遇到的那样),并且您正在使用Eclipse中的另一个项目作为库。

Do so: Right click project -> Properties -> Android -> Library -> Add

这样做:右键点击项目->属性-> Android ->库->添加

That did it for me! Adding a project as a library (Project Properties)

这对我有好处!将项目添加为库(项目属性)

#21


0  

Activity again added to manifest.I tried in my manifest then app worked.

活动再次添加到manifest中。我尝试了我的舱单,然后应用程序成功了。

 <activity
        android:name="com.xxx.xxx.MainActivity"

#22


0  

Try go to

试着去

  • Right click project
  • 右键单击项目
  • Java build path
  • Java构建路径
  • Source
  • right side -> Add folder button
  • 右侧->添加文件夹按钮
  • selected libs folder and OK
  • 选择libs文件夹和OK

I hope it helps.

我希望它有帮助。

#23


0  

Solutions:

解决方案:

  1. List item
  2. 列表项
  3. Check Exports Order
  4. 检查出口订单
  5. Enable Multi Dex
  6. 启用多敏捷
  7. Check api level of views in layout. I faced same problem with searchView. I have check api level while adding searchview but added implements SearchView.OnQueryTextListener to class file.
  8. 检查布局中视图的api级别。我在searchView遇到了同样的问题。在添加searchview时,我有检查api级别,但添加了实现searchview。OnQueryTextListener类文件。

#24


-4  

1)In Manifest file mention your activity name and action for it and also category . 2)In your Activity mention your starting contentview and mention your view id's in the activity.

1)在Manifest文件中提到你的活动名称和动作,以及类别。2)在你的活动中提到你的开始contentview,并在活动中提到你的视图id。

#1


126  

I had the same issue, I did the following to fix the problem.

我有同样的问题,我做了以下的修复问题。

  1. Go to "Properties" of the project.
  2. 进入项目的“属性”。
  3. Select "Java Build Path"
  4. 选择“Java构建路径”
  5. Select "Order and Export" Tab
  6. 选择“Order and Export”选项卡
  7. You should see the selected project's "src" and "gen" paths and dependencies here.
  8. 您应该在这里看到所选项目的“src”和“gen”路径和依赖项。
  9. The order how they listed were first "src" and then "gen" path
  10. 他们列出的顺序首先是“src”,然后是“gen”路径
  11. I switch them, so that "gen" folder is build before the "src"
  12. 我切换它们,这样“gen”文件夹在“src”之前构建

gen - automated code in project (from dependencies and references)
src - source code in project

项目中的自动化代码(来自依赖和引用)src -项目中的源代码

There was no need to restart the Eclipse. It just started working.

没有必要重新启动Eclipse。它刚刚开始工作。

Honestly I have never tried "Android Tools > Fix Project Properties", sometimes it might be doing the same thing. I do not know, I just did above after seen the error message, thinking something is wrong with the build paths.

老实说,我从来没有尝试过“Android Tools >修复项目属性”,有时它也会做同样的事情。我不知道,我只是在上面看到错误消息后才这么做,认为构建路径有问题。


Edit

编辑


Later on it was not sufficient, I was getting the error again. Then I "checked" all the dependencies listed in that view. Now it works again. So far so good. I will keep this updated if it fails again.

后来这还不够,我又犯了一次错误。然后我“检查”视图中列出的所有依赖项。现在工作了。目前为止一切都很顺利。如果它再次失败,我将保持更新。

FYI: in my last attempt, I tried "Android Tools > Fix Project Properties", but it didn't work out for me.

在我最后一次尝试中,我尝试了“Android Tools > Fix Project Properties”,但是没有成功。

#2


18  

I'm currently using SDK 20.0.3 and none of the previous solutions worked for me.

我目前正在使用SDK 20.0.3,以前的解决方案对我都不起作用。

I was able to get things to work by

我能把东西修好

  • Right clicking the Android project
  • 右击Android项目
  • Then selecting Build Path -> Link Source to bring up the Link Source dialog.
  • 然后选择构建路径—>链接源,打开链接源对话框。
  • Then I specified the 'src' folder of the Java project and gave it a name other than the default of 'src' (e.g. 'src2').
  • 然后,我指定了Java项目的“src”文件夹,并给它起了一个名称,而不是默认的“src”(例如)。“src2”)。
  • You can now right-click -> delete the new 'src2' folder.
  • 现在可以右键单击->删除新的“src2”文件夹。

This brought this created Java class files that were compiled for the Dalvik VM instead of the Java VM when the Android project was built. This allowed the Java class files in the Android Library jar file to go thru dexing when the Android project .apk was created. Now when the app was run the Java project classes were found instead of a Java.lang.NoClassDefFoundError being thrown.

这带来了创建的Java类文件,这些文件是在构建Android项目时为Dalvik VM而不是Java VM编译的。这允许在创建Android项目.apk时,Android库jar文件中的Java类文件通过dexing。现在,当应用程序运行时,找到的是Java项目类,而不是Java.lang。抛出NoClassDefFoundError。

If you want to use a jar file instead of linking the source, then you will need to create a Library Android project. (An Android Project with 'is library' checked in Properties -> Android.) You will then need to either link the source of the Java Project to the Android Library project as described above or copy the source files from the 'src' folder of the Java Project to the 'src' folder of the Android Library project. Build the Android Library project. Then you will be able copy the Android Project jar file that was created into the 'libs' folder of the Android folder because the class files in it were compiled for the Davlik VM instead of the Java VM when the Android project was built. This allows the Java class files in the Android Library jar file to go thru dexing when the Android project .apk is created. Now when the app is run the Java project classes will be found instead of a Java.lang.NoClassDefFoundError being thrown.

如果您想使用jar文件而不是链接源文件,那么您将需要创建一个库Android项目。(一个带有“is库”属性的Android项目——> Android。)然后,您需要将Java项目的源链接到上面描述的Android库项目,或者将源文件从Java项目的“src”文件夹复制到Android库项目的“src”文件夹。构建Android库项目。然后,您就可以将Android项目jar文件复制到Android文件夹的“libs”文件夹中,因为其中的类文件是在构建Android项目时为Davlik VM而不是Java VM编译的。这允许在创建Android项目.apk时,Android库jar文件中的Java类文件通过dexing。现在,当应用程序运行时,将找到Java项目类,而不是Java.lang。抛出NoClassDefFoundError。

#3


17  

Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using. i got the solution by following below link NoClassDefFoundError Android Project?

尝试进入项目->属性-> Java构建路径->订单和导出,并确保Android私有库为您的项目和您正在使用的所有其他库项目检查。我通过以下链接NoClassDefFoundError Android项目得到了解决方案?

#4


8  

Just in case it helps someone, I faced the same issue. My jar file was under the libs directory and the jar was added to the build path. Still it was throwing that exception.

为了防止它对某人有所帮助,我遇到了同样的问题。我的jar文件在libs目录下,jar被添加到构建路径中。它仍然抛出了这个例外。

I just cleaned the project and it worked for me.

我刚刚清理了这个项目,它对我起了作用。

Eclipse -> Project -> Clean -> Select the project and clean

Eclipse ->项目-> Clean ->选择项目并Clean

#5


7  

I tried all of the above said solutions but did not worked out for me, Here is what i did to get it done project-> config build path-> order and export-> move dependent project on top

我尝试了以上所有的解决方案,但并没有为我解决,这里是我所做的项目->配置构建路径->订单和export->在上面的依赖项目。

#6


6  

This error is also generated when you make an app that uses the Google API (such as Maps) but run it on a device that targets the Android API.

当您创建的应用程序使用谷歌API(如Maps),但在针对Android API的设备上运行时,也会产生此错误。

#7


5  

I encountered this NoClassDefFoundError when I used java.nio.charset.StandardCharsets.

我在使用java.nio.charset.StandardCharsets时遇到了这个NoClassDefFoundError。

The reason is that StandardCharsets has not existed until JRE 1.7. If I make the java compile version set to 1.7, Eclipse complained that "Android requires compiler compliance level 5.0 or 6.0". So, I fixed it by right-click the project name->Android Tools->Fix Project Properties. It is compiled with JRE1.6.

原因是标准字符集直到JRE 1.7才存在。如果我将java编译版本设置为1.7,Eclipse会抱怨说“Android要求编译器遵循5.0或6.0级”。因此,我通过右键单击项目名称>Android Tools->Fix项目属性来修复它。它是用JRE1.6编译的。

However, because StandardCharsets has not existed until 1.7. It reported NoClassDefFoundError when I ran it.

但是,因为标准字符集直到1.7才存在。当我运行它时,它报告了NoClassDefFoundError。

I has not come to realize this until after trying a lot of other methods including reinstalling JDK. The real reason is clearly told by the meaning of NoClassDefFoundError: The class cannot be found at run time although it passed compilation.

在尝试了许多其他方法,包括重新安装JDK之后,我才意识到这一点。NoClassDefFoundError的意思清楚地说明了真正的原因:类虽然通过编译,但在运行时却无法找到。

General conclusion is that as long as Android does not work with JRE 1.7, if you use any new feature provided since 1.7, you will encounter this error.

一般的结论是,只要Android不支持JRE 1.7,如果使用自1.7以来提供的任何新特性,就会遇到这个错误。

My solution is that I copied those source code into my code!

我的解决方案是将这些源代码复制到我的代码中!

#8


4  

The NoClassDefFoundError description is, from the SO tag:

NoClassDefFoundError描述来自SO标记:

The Java Error thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found. The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

如果Java虚拟机或类加载器实例试图装入类的定义(作为普通方法调用的一部分或使用新表达式创建新实例的一部分),并且找不到类的定义,则会抛出Java错误。当当前正在执行的类被编译时,存在搜索类定义,但是不能再找到定义。

Or better:

或更好:

NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time.

Java的NoClassDefFoundError在Java虚拟机无法在运行时找到特定的类时出现,在编译时可用。

from this page. Check it, there are some ways to solve the error. I hope it helps.

从这个页面。检查一下,有一些方法可以解决这个问题。我希望它有帮助。

#9


3  

For me this problem was related to the API that I was using not being deployed. For example, I used a ZSDK_API.jar as a reference.

对我来说,这个问题与我没有部署的API有关。例如,我使用了ZSDK_API。jar作为参考。

To fix the issue I had to right click on the project and select properties. From JAVA BUILD PATH, I had to add the API that was not being deployed. This was weird as the app was throwing MainActivity class not found and in reality the error was caused by the DiscoveryHandler class not being found.

为了解决这个问题,我必须右键单击项目并选择properties。从JAVA构建路径中,我必须添加没有部署的API。这很奇怪,因为应用程序抛出了未找到的MainActivity类,实际上错误是由于未找到DiscoveryHandler类而导致的。

Hopes this helps someone.

希望这可以帮助别人。

#10


3  

In my case, I was trying to add a normal java class (from a normal java project) compiled with jre 1.7 to an android app project compiled with jre 1.7.

在我的例子中,我试图将一个用jre 1.7编译的普通java类(来自普通java项目)添加到一个用jre 1.7编译的android应用程序项目中。

The solution was to recompile that normal java class with jre 1.6 and add references to the android app project (compiled with jre 1.6 also) as usual (in tab order and export be sure to check the class, project, etc).

解决方案是使用jre 1.6重新编译普通java类,并像往常一样添加对android应用程序项目的引用(也使用jre 1.6编译)(按tab顺序导出,确保检查类、项目等)。

The same process, when using an android library to reference external normal java classes.

同样的过程,当使用android库引用外部普通java类时。

Don't know what's wrong with jre 1.7, when compiling normal java classes from a normal java project and try to reference them in android app or android library projects.

不知道jre 1.7有什么问题,当从普通java项目编译普通java类并试图在android应用程序或android库项目中引用它们时。

If you don't use normal java classes (from a normal java project) you don't need to downgrade to jre 1.6.

如果不使用普通java类(来自普通java项目),则不需要降级到jre 1.6。

#11


2  

I met NoClassDefFoundError for a class that exists in my project (not a library class). The class exists but i got NoClassDefFoundError. In my case, the problem was multidex support. The problem and solution is here: Android Multidex and support libraries

我遇到了NoClassDefFoundError,因为在我的项目中存在一个类(而不是一个库类)。这个班存在,但我没有找到。在我的案例中,问题是multidex支持。问题和解决方案在这里:Android Multidex和支持库。

You get this error for Android versions lower than 5.0.

对于低于5.0的Android版本,您会得到这个错误。

#12


1  

Other idea. For example, you have class derived from "android.support.v4.app.Fragment".

其他的想法。例如,类派生自“android.support.v4.app.Fragment”。

However you made a mistake and inherited it from "android.app.Fragment". Then you will have this error on the Android 2 devices.

然而,您犯了一个错误,并从“android.app.Fragment”继承了这个错误。然后在Android 2设备上就会出现这个错误。

#13


1  

I have just figured out something with this error.

我刚刚算出了这个误差。

Just make sure that the library jar file contains the compiled R class under android.support.v7.appcompat package and copy all the res in the v7 appcompat support "project" in your ANDROID_SDK_HOME/extras/android/support/v7/appcompat folder.

确保库jar文件包含android.support.v7下编译好的R类。appcompat包并复制v7 appcompat支持“项目”中的所有res在您的ANDROID_SDK_HOME/extras/android/support/v7/appcompat文件夹中。

I use Netbeans with the Android plugin and this solved my issue.

我使用Netbeans和Android插件,这解决了我的问题。

#14


1  

I am guessing that you don't specify javac's target when creating the common library, so javac automatically uses the latest available target, which is likely 1.7 (Java7) or 1.8 (Java8).

我猜您在创建公共库时没有指定javac的目标,因此javac会自动使用最新的可用目标,可能是1.7 (Java7)或1.8 (Java8)。

It has already been stated that

已经说过了

Android requires compiler compliance level 5.0 or 6.0

Android要求编译器遵循5.0或6.0级

dx of Android's build tools < 19.0.0 isn't able to convert Java7 (or higher) bytecode to Dalvik bytecode.

dx的Android构建工具< 19.0.0不能将Java7(或更高)字节码转换为Dalvik字节码。

So either use a build tools version >= 19.0.0 or use javac with -target 6, by modifying for example your ant build.xml like this:

因此,要么使用构建工具版本的>= 19.0.0,要么使用带有-target 6的javac,通过修改ant构建示例。xml是这样的:

<javac
srcdir="src/"
destdir="build/"
target="6"
/>

#15


1  

On Android Studio:

在Android上工作室:

1) Add multiDexEnabled = true in your default Config

1)在默认配置中添加multiDexEnabled = true

2) Add compile com.android.support:multidex:1.0.0 in your dependencies

2)添加编译com.android.support:multidex:1.0.0

3) Application class extend MultiDexApplication instead of just Application

应用程序类扩展MultiDexApplication,而不仅仅是Application

#16


0  

I fixed this issue by adding library project path in project.propertied manually. some how eclipse did not added this entry automaticvally along with "add project". so the point where app was trying to refer any componenrt inside lib project it was crashing .

我通过在project中添加library project path解决了这个问题。手动产。一些eclipse没有在“添加项目”的同时自动添加这个条目的方法。所以当app试图在lib项目中引用任何组件时它崩溃了。

you also can try the same thing . app dependecy in projec.properties like

你也可以尝试同样的事情。应用在projec dependecy。属性如

android.library.reference.1=....\android-sdks\extras\google\google_play_services\libproject/google-play-services_lib

android.library.reference.1 = ....谷歌\ android-sdks \配件\ \ google_play_services \ libproject / google-play-services_lib

and run .

和运行。

#17


0  

jars used to be in the lib/ folder, now they're in libs/ If you use lib, you can move your jars from lib to libs, and remove the dependencies from project properties/java build path because Android will now find them automatically.

jar过去在lib/文件夹中,现在在libs/如果您使用lib,您可以将jar从lib移动到libs,并从项目属性/java构建路径中删除依赖项,因为Android现在将自动找到它们。

#18


0  

For me, the issue was that the referenced library was built using java 7. I solved this by rebuilding using the 1.6 JDK.

对我来说,问题是引用的库是使用java 7构建的。通过使用1.6 JDK,我解决了这个问题。

#19


0  

Some time java.lang.NoClassDefFoundError: error appear when use ART instead of Dalvik runtime. To change runtime just go to Developer Option -> Select Runtime -> Dalvik.

一些时间. lang。NoClassDefFoundError:当使用ART而不是Dalvik运行时,会出现错误。要更改运行时,只需切换到Developer选项->选择运行时-> Dalvik。

#20


0  

If none of the above works (like it happened to me), and you're using as a library another project in Eclipse.

如果上面的任何一个都不起作用(就像我遇到的那样),并且您正在使用Eclipse中的另一个项目作为库。

Do so: Right click project -> Properties -> Android -> Library -> Add

这样做:右键点击项目->属性-> Android ->库->添加

That did it for me! Adding a project as a library (Project Properties)

这对我有好处!将项目添加为库(项目属性)

#21


0  

Activity again added to manifest.I tried in my manifest then app worked.

活动再次添加到manifest中。我尝试了我的舱单,然后应用程序成功了。

 <activity
        android:name="com.xxx.xxx.MainActivity"

#22


0  

Try go to

试着去

  • Right click project
  • 右键单击项目
  • Java build path
  • Java构建路径
  • Source
  • right side -> Add folder button
  • 右侧->添加文件夹按钮
  • selected libs folder and OK
  • 选择libs文件夹和OK

I hope it helps.

我希望它有帮助。

#23


0  

Solutions:

解决方案:

  1. List item
  2. 列表项
  3. Check Exports Order
  4. 检查出口订单
  5. Enable Multi Dex
  6. 启用多敏捷
  7. Check api level of views in layout. I faced same problem with searchView. I have check api level while adding searchview but added implements SearchView.OnQueryTextListener to class file.
  8. 检查布局中视图的api级别。我在searchView遇到了同样的问题。在添加searchview时,我有检查api级别,但添加了实现searchview。OnQueryTextListener类文件。

#24


-4  

1)In Manifest file mention your activity name and action for it and also category . 2)In your Activity mention your starting contentview and mention your view id's in the activity.

1)在Manifest文件中提到你的活动名称和动作,以及类别。2)在你的活动中提到你的开始contentview,并在活动中提到你的视图id。