简体   繁体   English

onStart方法中的NoClassDefFoundError-Android

[英]NoClassDefFoundError in onStart method - Android

I am implementing Amazon IAP into my Media player app. 我正在将Amazon IAP实施到我的媒体播放器应用程序中。 I have registered my observer as it was said in Amazon docs. 我已经按照Amazon文档中的说明注册了观察者。 But, when I ran the project it is throwing NoClassDefFoundError . 但是,当我运行该项目时,它会抛出NoClassDefFoundError

There is no compilation error in the project and the class is right there in the project with correct package name. 项目中没有编译错误,并且类在项目中正确的包名称下。 Searched other forums but not able to solve the issue. 搜索了其他论坛,但无法解决问题。

Any help is greatly appreciated!! 任何帮助是极大的赞赏!!

11-08 21:02:07.399: E/AndroidRuntime(11667): FATAL EXCEPTION: main
11-08 21:02:07.399: E/AndroidRuntime(11667): java.lang.NoClassDefFoundError: com.songs.mysongs.PlaySongObserver
11-08 21:02:07.399: E/AndroidRuntime(11667):    at com.songs.mysongs.PlaySongActivity.onStart(PlaySongActivity.java:111)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at android.app.Activity.performStart(Activity.java:4639)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1972)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2024)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at android.app.ActivityThread.access$600(ActivityThread.java:126)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at android.os.Looper.loop(Looper.java:137)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at android.app.ActivityThread.main(ActivityThread.java:4479)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at java.lang.reflect.Method.invokeNative(Native Method)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at java.lang.reflect.Method.invoke(Method.java:511)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-08 21:02:07.399: E/AndroidRuntime(11667):    at dalvik.system.NativeStart.main(Native Method)

Try this.If you are using new SDK there is quite different way of adding library in the project. 尝试一下。如果您正在使用新的SDK ,则在项目中添加库的方法完全不同。

  1. Create folder named as libs in your project and place your library over there. 在项目中创建名为libs文件夹,然后将库放置在该文件夹中。
  2. Right click on your project > Build Path > Add External Archives 右键单击您的项目>构建路径>添加外部档案

I hope this will resolve your issue.If you have already added the library by using add external library then try to follow the steps which I mention. 希望这能解决您的问题。如果您已经使用添加外部库添加了库,请尝试按照我提到的步骤进行操作。

NoClassDefFoundError because of following: 由于以下原因,导致NoClassDefFoundError

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. 如果Java虚拟机或ClassLoader实例尝试加载类的定义(作为常规方法调用的一部分或使用新表达式创建新实例的一部分)而抛出,则找不到该类的定义。

In your case com.songs.mysongs.PlaySongObserver class are not found by JVM. 在您的情况下,JVM找不到com.songs.mysongs.PlaySongObserver类。 So you have to check might be your class path is not properly set Or if you are using IDE (like Eclipse) then check is that class is selected for run time. 因此,您必须检查是否可能未正确设置您的类路径,或者如果您使用的是IDE(如Eclipse),请检查是否已选择运行时类。

添加jar之后,检查它是否要导出到。

Cleaning the project has resolved NoClassDefFoundError with the purchasing observer in my case; 在我的案例中,清理项目已通过采购观察员解决了NoClassDefFoundError; I guess .jar libraries are not always picked up automatically? 我猜.jar库不是总是自动拾取吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM