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

Solution 1:

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

Solution 2:

In my case

  1. clean project
  2. invalidate and restart

it's work

Solution 3:

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.

Solution 4:

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);
}
}