android - ActionBarActivity - NoClassDefFoundError 异常

标签 android noclassdeffounderror buildpath android-actionbar-compat android-actionbaractivity

已看过:NoClassDefFoundError Android with ActionBarActivityActionBarActivity catch an error on Phone

我正在尝试在我的项目中使用ActionBarCompact。我已经链接了 android-support-v7 项目及其 jar 在我的项目中,并检查了许多来源的步骤,但我仍然无法处理该问题。

当我构建项目时,没有错误,但运行时出现异常。不知道为什么没有检测到类(class)。请告诉我出了什么问题。谢谢。

代码:

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.widget.ArrayAdapter;

public class mainMenu extends ActionBarActivity implements ActionBar.OnNavigationListener {

    ActionBar actionbar;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menutab);

        actionbar = getSupportActionBar();
        actionbar.setTitle("Menu");
        actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

        ArrayAdapter<CharSequence> mSpinnerAdapter = ArrayAdapter.createFromResource(this,R.array.menu_items, R.id.simpleText);
        actionbar.setListNavigationCallbacks(mSpinnerAdapter, this);
    }

    @Override
    public boolean onNavigationItemSelected(int arg0, long arg1)//item pos, itemid
    {
        switch (arg0) {
        case 0:
            System.out.println("selected: " + arg0);
            break;
        case 1:
            System.out.println("selected: " + arg0);
            break;
        case 2:
            System.out.println("selected: " + arg0);
            break;
        case 3:
            System.out.println("selected: " + arg0);
            break;
        default:
            break;
        }
        return true;
    }
}

------------项目结构和构建路径------------------

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Logcat

enter image description here

最佳答案

试试这个:

  • “sdk/extras/android/support/v7/appcompat”将支持库作为项目导入

  • 项目中的引用库(对于 Eclipse,“Properties - Android - Add”)。

  • 构建项目(对于 Eclipse,“项目 - 构建全部”)。确保您的主项目 gen 文件夹中有“android.support.v7.appcompat”

如果仍然不能解决您的问题,请重新启动 eclipse。

然后清理并重建项目

如果问题仍然存在,请从您的计算机中删除支持库并重新下载,然后按照上述步骤操作。

关于android - ActionBarActivity - NoClassDefFoundError 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18848578/

相关文章:

android - ListView中滚动时调用哪个函数

android - 我应该将 OkHttp 与 Volley 库一起使用吗?

android - 异步任务结束后开始 Intent

.jar 中的 Java 调用函数

java - 使用 twillo 应用程序使用 java 发送短信时出错

java - 无法使用eclipse引用java中的项目

java - 解析带时区的日期字符串 java

java - 使用oracle webservices代理时出现错误: java. lang.NoClassDefFoundError: org/codehaus/stax2/XMLInputFactory2

java - 将库导入到 Android 项目中?

java - Android eclipse - android.jar 在 libs 文件夹和引用的库中重复