Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14 in Android Studio

Here's the log.

java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14
        at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:93)
        at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:77)
        at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:429)
        at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:57)
        at com.marshall.gruppo.ui.MainScreenActivity.onCreate(MainScreenActivity.java:41)
        at android.app.Activity.performCreate(Activity.java:5451)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
        at android.app.ActivityThread.access$900(ActivityThread.java:175)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:146)
        at android.app.ActivityThread.main(ActivityThread.java:5602)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        at dalvik.system.NativeStart.main(Native Method)

I also read an article suggesting the solution (java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14). It suggests me to add the following in the build.gradle file.

compile 'com.android.support:appcompat-v7:22.2.0'

Actually that was already in the file, and it seems like it's not the original issue here. Here is my build.gradle file.

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile project(':volley')
compile project(':android-support-v4')
}

In case you need to have a look at my code, here's my code that is causing the NoClassDefFoundError.

public class MainScreenActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;

private CharSequence mDrawerTitle;

private CharSequence mTitle;

private String[] navMenuTitles;
private TypedArray navMenuIcons;

private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mainscreen);

    mTitle = mDrawerTitle = getTitle();

    navMenuTitles = getResources().getStringArray(R.array.drawermenu_items);

    navMenuIcons = getResources()
            .obtainTypedArray(R.array.drawermenu_icons);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.list_slidermenu);

    navDrawerItems = new ArrayList<NavDrawerItem>();

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1), true, "50+"));


    navMenuIcons.recycle();

    mDrawerList.setOnItemClickListener(new SlideMenuClickListener());

    adapter = new NavDrawerListAdapter(getApplicationContext(),
            navDrawerItems);
    mDrawerList.setAdapter(adapter);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.app_name, R.string.app_name) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        displayView(0);
    }
}

Here's the additional error log. There might be a hint for the solution.

07-06 17:50:03.056  27850-27850/com.marshall.gruppo E/dalvikvm﹕ Could not find class 'android.support.v7.app.AppCompatDelegateImplV14', referenced from method android.support.v7.app.AppCompatDelegate.create
07-06 17:50:03.056  27850-27850/com.marshall.gruppo E/dalvikvm﹕ Could not find class 'android.support.v7.app.AppCompatDelegateImplV11', referenced from method android.support.v7.app.AppCompatDelegate.create
07-06 17:50:03.056  27850-27850/com.marshall.gruppo E/dalvikvm﹕ Could not find class 'android.support.v7.app.AppCompatDelegateImplV7', referenced from method android.support.v7.app.AppCompatDelegate.create

and here's the xml file for the activity.

<?xml version="1.0" encoding="UTF-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ListView
    android:id="@+id/list_slidermenu"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@color/list_divider"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_selector"
    android:background="@color/list_background"/>

like image 558
MarshallLee Avatar asked Jul 06 '15 15:07

MarshallLee


2 Answers

there might be a conflict with your dependencies

try removing

compile project(':android-support-v4')
like image 167
lababo Avatar answered Nov 19 '22 06:11

lababo


I had the same error and FULLY enabling multidex worked for me. here is what I did in gradle and manifest files

android {
compileSdkVersion 21
buildToolsVersion "21.1.0"

defaultConfig {
    ...
    minSdkVersion 14
    targetSdkVersion 21
    ...

    // Enabling multidex support.
    multiDexEnabled true
}
...
}

dependencies {
compile 'com.android.support:multidex:1.0.0'
}

also in my manifest file, I have add the MultiDexApplication class from the multidex support library to the application element like this

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.android.multidex.myapplication">
   <application
       ...
       android:name="android.support.multidex.MultiDexApplication">
       ...
   </application>
</manifest>
like image 37
smoothumut Avatar answered Nov 19 '22 07:11

smoothumut