如何解决" NoClassDefFoundError"?

时间:2015-01-09 08:20:15

标签: android

我在stackoverflow中提到了与此问题相关的一些问题。但不幸的是,没有解决问题。例如,我尝试更改构建路径中srcgen文件夹的顺序。

现在我运行App时。我收到

01-09 09:12:36.931: E/dalvikvm(24536): Could not find class 'com.example.mqtt_designlayout_00.MainActivity$1', referenced from method com.example.mqtt_designlayout_00.MainActivity.setUpNavDrawer

logcat输出:

01-09 09:17:18.311: E/AndroidRuntime(24869): FATAL EXCEPTION: main
01-09 09:17:18.311: E/AndroidRuntime(24869): Process: com.example.mqtt_designlayout_00, PID:   
24869
01-09 09:17:18.311: E/AndroidRuntime(24869): java.lang.NoClassDefFoundError:   
com.example.mqtt_designlayout_00.MainActivity$1

01-09 09:17:18.311: E/AndroidRuntime(24869):    at  
com.example.mqtt_designlayout_00.MainActivity.setUpNavDrawer(MainActivity.java:124)
01-09 09:17:18.311: E/AndroidRuntime(24869):    at com.   
example.mqtt_designlayout_00.MainActivity.initViews(MainActivity.java:104)
01-09 09:17:18.311: E/AndroidRuntime(24869):    at 
com.example.mqtt_designlayout_00.MainActivity.onCreate(MainActivity.java:43)
01-09 09:17:18.311: E/AndroidRuntime(24869):    at  
android.app.Activity.performCreate(Activity.java:5389)
01-09 09:17:18.311: E/AndroidRuntime(24869):    at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)

01-09 09:17:18.311: E/AndroidRuntime(24869):    at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)

代码

eclipse将此行指出为错误:navDrawerToggle = new ActionBarDrawerToggle(MainActivity.this, navDrawerLayout, R.string.navdrawer_opened, R.string.navdrawer_closed)

private void setUpNavDrawer() {
    // TODO Auto-generated method stub
    navDrawerModel = new ArrayList<NavDrawerModell>();
    navDrawerModel.add(new NavDrawerModell(navDrawerIcons.getResourceId(0, -1), navDrawerOptions[0], ECO_ASSISTANT_DESC));
    navDrawerModel.add(new NavDrawerModell(navDrawerIcons.getResourceId(1, -1), navDrawerOptions[1], DATA_LOGGER_DESC));
    navDrawerModel.add(new NavDrawerModell(navDrawerIcons.getResourceId(2, -1), navDrawerOptions[2], ECO_ASSISTANT_DESC));
    navDrawerIcons.recycle(); // to recycle the typed array. never touch the typed array after this line.

    adapter = new NavDrawerListAdapter(getApplicationContext(), this.navDrawerModel);
    drawerListView.setAdapter(adapter);

    // enabling action bar app icon and behaving it as toggle button
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mTitle = mDrawerTitle = getTitle();

    navDrawerToggle = new ActionBarDrawerToggle(MainActivity.this, navDrawerLayout, R.string.navdrawer_opened, R.string.navdrawer_closed) {

        @Override
        public void onDrawerOpened(View drawerView) {
            // TODO Auto-generated method stub
            super.onDrawerOpened(drawerView);
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // calling onPrepareOptionsMenu() to hide action bar icons
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            // TODO Auto-generated method stub
            super.onDrawerClosed(drawerView);
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // calling onPrepareOptionsMenu() to show action bar icons
        }
    };
    navDrawerLayout.setDrawerListener(navDrawerToggle);
    drawerListView.setOnItemClickListener(new SlideMenuClickListener());
}

1 个答案:

答案 0 :(得分:1)

当您的代码所依赖的类文件存在于编译时但在运行时未找到时,会导致这种情况。查找构建时和运行时类路径的差异。