简体   繁体   English

android-support-v4.jar在构建路径上,但出现noClassDefFoundError

[英]android-support-v4.jar is on build path but getting noClassDefFoundError

I've an app that uses the android-support-v4.jar. 我有一个使用android-support-v4.jar的应用程序。 This jar is on the build path in eclipse. 这个jar位于Eclipse的构建路径中。 If i right click on the package and configure build path, it is present there as a library. 如果我右键单击该软件包并配置构建路径,则该路径将作为库存在。 In the source code i can use it and eclipse knows what it is, but if i run the app i get this runtime error 在源代码中,我可以使用它,并且eclipse知道它是什么,但是如果我运行该应用程序,则会收到此运行时错误

01-13 15:39:51.838: E/AndroidRuntime(12398): FATAL EXCEPTION: main
01-13 15:39:51.838: E/AndroidRuntime(12398): java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager
01-13 15:39:51.838: E/AndroidRuntime(12398):    at com.carefreegroup.NfcscannerActivity.processTagWithGPS(NfcscannerActivity.java:1568)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at com.carefreegroup.NfcscannerActivity.onActivityResult(NfcscannerActivity.java:1742)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at android.app.Activity.dispatchActivityResult(Activity.java:4747)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3394)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3448)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at android.app.ActivityThread.access$1100(ActivityThread.java:139)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at android.os.Looper.loop(Looper.java:156)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at android.app.ActivityThread.main(ActivityThread.java:4987)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at java.lang.reflect.Method.invokeNative(Native Method)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at java.lang.reflect.Method.invoke(Method.java:511)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-13 15:39:51.838: E/AndroidRuntime(12398):    at dalvik.system.NativeStart.main(Native Method)

Has anybody any ideas why? 有谁知道为什么吗? Thanks in advance. 提前致谢。

This jar is on the build path in eclipse. 这个jar位于Eclipse的构建路径中。

If you did this by manually fiddling with the build path, that is the source of your difficulty. 如果您通过手动摆弄构建路径来执行此操作,那么这就是您的困难所在。 Put the JAR in libs/ of your project and undo your build path change. 将JAR放在项目的libs/ ,并撤消对构建路径的更改。 Everything in libs/ is automatically added to your compile build path and is packaged into your APK for distribution to the device. libs/都会自动添加到您的编译构建路径中并打包到您的APK中以分发到设备。

Put the jar file in the libs/ folder so it's in your project's workspace as well. 将jar文件放在libs /文件夹中,使其也位于项目的工作区中。 This is how I've always done it without issue. 这就是我一直没有问题地做到的方式。

Drag the .jar to the libs folder and then point to it in the build path properties. 将.jar拖到libs文件夹,然后在构建路径属性中指向它。

This problem was hounding me for almost Six months now and no solution was helping me but today I have managed to find the correct solution on my own. 这个问题困扰着我近六个月,没有解决方案对我有帮助,但是今天我已经设法自己找到了正确的解决方案。

When you select you project target version to be more than or equal to Android 4.0 Android SDK includes "android-support-v4.jar" file in your projects "libs" folder.This jar contains all the classes and methods related Android 4.0 or later 选择项目目标版本大于或等于Android 4.0时,Android SDK在项目的“ libs”文件夹中包含“ android-support-v4.jar”文件。此jar包含与Android 4.0或更高版本相关的所有类和方法

You can see your problem, android is trying to find the class definition which is in "android-support-v4.jar" so that means you have not configured the build path to the "android-support-v4.jar" file.To do this follow these steps: 您可以看到您的问题,android正在尝试查找“ android-support-v4.jar”中的类定义,因此这意味着您尚未配置“ android-support-v4.jar”文件的构建路径。请按照以下步骤操作:

1.Open your project properties 1.打开项目属性
2.Select "Java Build Path" from left side menu 2.从左侧菜单中选择“ Java构建路径”
3.Select "Libraries" tab 3.选择“库”标签
4.Press "Add External Jar" 4.按“添加外部罐子”
5.MOST IMPORTANT STEPS :- 5.最重要的步骤:
Select "android-support-v4" jar file of "libs" folder of YOUR CURRENT PROJECT LOCATION(Path Should be of your project only and not the android sdk). 在当前项目位置的“ libs”文件夹中选择“ android-support-v4” jar文件(路径应仅是您的项目,而不是android sdk)。
6.Select "Order and Export" tab and "TICK" the checkbox of "android-support-v4.jar" 6.选择“订单和导出”标签,然后选中“ android-support-v4.jar”复选框

That's it, your done !! 就是这样,您完成了!

  1. Put the android-support-v4.jar in libs/ of your project 将android-support-v4.jar放入项目的libs /中
  2. Put the wearable-preview-support.jar in libs/ of your project 将wearable-preview-support.jar放入项目的libs /中

clean build, it worked for me. 干净的构建,对我有用。

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

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