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

时间:2015-07-06 15:32:16

标签: java android noclassdeffounderror

这是日志。

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)

我还阅读了一篇建议解决方案的文章(java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14)。它建议我在build.gradle文件中添加以下内容。

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

实际上已经存在于文件中,而且似乎这不是原始问题。这是我的build.gradle文件。

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

如果您需要查看我的代码,请查看导致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);
    }
}

这是附加的错误日志。可能会有解决方案的提示。

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

并且这里是活动的xml文件。

<?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"/>

2 个答案:

答案 0 :(得分:2)

可能与您的依赖项存在冲突

尝试删除

<?php 
session_start();
$new_url=$_POST['url1'];
?>

<script type="text/javascript">   
function isValidURL() {
 alert('<?php echo "ajax".$new_url;?>');
   $.ajax({
          url: "('<?php echo $new_url;?>')",

          success: function(xml, textStatus, xhr) {
        //console.log(arguments);
        console.log(xhr.status);
        alert("11111");
        alert(xhr.status);
    },
    complete: function(xhr, textStatus) {
        console.log(xhr.status);
        alert("22222");
        alert(xhr.status);
        alert(textStatus);

    } 
});
}


var isValid = isValidURL();
</script>
</head>

答案 1 :(得分:1)

我有同样的错误,并且完全启用multidex为我工作。这是我在gradle和manifest文件中所做的事情

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'
}

同样在我的清单文件中,我已将multidex支持库中的MultiDexApplication类添加到这样的应用程序元素中

<?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>