turtleboy
turtleboy

Reputation: 7572

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

I've an app that uses the android-support-v4.jar. This jar is on the build path in 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

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.

Upvotes: 0

Views: 4265

Answers (4)

Alok
Alok

Reputation: 1

  1. Put the android-support-v4.jar in libs/ of your project
  2. Put the wearable-preview-support.jar in libs/ of your project

clean build, it worked for me.

Upvotes: 0

Rauf
Rauf

Reputation: 618

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

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:

1.Open your project properties
2.Select "Java Build Path" from left side menu
3.Select "Libraries" tab
4.Press "Add External Jar"
5.MOST IMPORTANT STEPS :-
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).
6.Select "Order and Export" tab and "TICK" the checkbox of "android-support-v4.jar"

That's it, your done !!

Upvotes: 2

RED_
RED_

Reputation: 3007

Put the jar file in the libs/ folder so it's in your project's workspace as well. 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.

Upvotes: 4

CommonsWare
CommonsWare

Reputation: 1006614

This jar is on the build path in 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. Everything in libs/ is automatically added to your compile build path and is packaged into your APK for distribution to the device.

Upvotes: 4

Related Questions