Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/os/BuildCompat

I have updated the AppCompat libraries to 24.2.1 and the SDK to Android 7 in my Eclipse install. Since that, I'm not capable to run any of my apps. I appreciate if you can help a bit with that...

E/AndroidRuntime(17555): java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/os/BuildCompat;
E/AndroidRuntime(17555):    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:196)
E/AndroidRuntime(17555):    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181)
E/AndroidRuntime(17555):    at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521)
E/AndroidRuntime(17555):    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
E/AndroidRuntime(17555):    at com.ryosoftware.calendareventsnotifier.MainActivity.onCreate(MainActivity.java:844)
E/AndroidRuntime(17555):    at android.app.Activity.performCreate(Activity.java:5990)
E/AndroidRuntime(17555):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
E/AndroidRuntime(17555):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
E/AndroidRuntime(17555):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
E/AndroidRuntime(17555):    at android.app.ActivityThread.access$900(ActivityThread.java:154)
E/AndroidRuntime(17555):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
E/AndroidRuntime(17555):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(17555):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(17555):    at android.app.ActivityThread.main(ActivityThread.java:5294)
E/AndroidRuntime(17555):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17555):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(17555):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
E/AndroidRuntime(17555):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
E/AndroidRuntime(17555): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.os.BuildCompat" on path: DexPathList[[zip file "/data/app/com.ryosoftware.calendareventsnotifier-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime(17555):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(17555):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(17555):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(17555):    ... 18 more
E/AndroidRuntime(17555):    Suppressed: java.lang.ClassNotFoundException: android.support.v4.os.BuildCompat
E/AndroidRuntime(17555):        at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(17555):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(17555):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(17555):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(17555):        ... 19 more
E/AndroidRuntime(17555):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
like image 273
The Matrix Avatar asked Sep 20 '16 18:09

The Matrix


4 Answers

You are getting NoClassDefFoundError & ClassNotFoundException

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

FYI

You are using Eclipse. Android Studio is a far simpler way to develop for Android if you manage to get the hang of it. For developers who have been using Eclipse, migrating to Studio is a nightmare for them. Eclipse is dead (My personal opinion).

For your NoClassDefFoundError problem goto rebuild option under Project > Clean and then select the project you want to clean up .Then Restart your Eclipse and run again .

Solutions

Check your classpath contains that jar (AppCompat), if your classpath doesn't contain the jar then just add that class in your classpath.

You should Use Android Studio instead of Eclipse . Read

  1. Support Library Features

The Gradle build script dependency identifier for this library is as follows:

com.android.support:appcompat-v7:24.2.1

Then Clean-Rebuild-Restart IDE

like image 104
IntelliJ Amiya Avatar answered Nov 20 '22 19:11

IntelliJ Amiya


In my case

  1. clean project
  2. invalidate and restart

it's work

like image 40
Lonie Avatar answered Nov 20 '22 21:11

Lonie


Another ugly reason for this to be caused is if you're trying to attach a debugger with breakpoint on something that happens during Activity creation.

like image 5
Rock_Artist Avatar answered Nov 20 '22 21:11

Rock_Artist


I added two classes in my java package and its working fine, keep both class as showing in below image:

enter image description here

AsyncTaskCompat.java

public class AsyncTaskCompat {

/**
 * Executes the task with the specified parameters, allowing multiple tasks to run in parallel
 * on a pool of threads managed by {@link android.os.AsyncTask}.
 *
 * @param task The {@link android.os.AsyncTask} to execute.
 * @param params The parameters of the task.
 * @return the instance of AsyncTask.
 */
public static <Params, Progress, Result> AsyncTask<Params, Progress, Result> executeParallel(
        AsyncTask<Params, Progress, Result> task, Params... params) {
    if (task == null) {
        throw new IllegalArgumentException("task can not be null");
    }

    if (Build.VERSION.SDK_INT >= 11) {
        // From API 11 onwards, we need to manually select the THREAD_POOL_EXECUTOR
        AsyncTaskCompatHoneycomb.executeParallel(task, params);
    } else {
        // Before API 11, all tasks were run in parallel
        task.execute(params);
    }

    return task;
}
}

AsyncTaskCompatHoneycomb.java

class AsyncTaskCompatHoneycomb {

static <Params, Progress, Result> void executeParallel(
        AsyncTask<Params, Progress, Result> task, Params... params) {
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
}
like image 3
varotariya vajsi Avatar answered Nov 20 '22 19:11

varotariya vajsi