eclipse ActionBarSherlock:java.lang.NoClassDefFoundError:com.actionbarsherlock.R$styleable

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11443262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:33:25  来源:igfitidea点击:

ActionBarSherlock: java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable

androideclipseactionbarsherlocknoclassdeffounderror

提问by Michael Hampton

I am trying to build a tiny sample application with ActionBarSherlock 4.1 using Eclipse Indigo and ADT r20.

我正在尝试使用 Eclipse Indigo 和 ADT r20 使用 ActionBarSherlock 4.1 构建一个小型示例应用程序。

I created a new Android project with a blank activity, copied actionbarsherlock.jar to libs and referenced it in the build path.

我创建了一个带有空白活动的新 Android 项目,将 actionbarsherlock.jar 复制到 libs 并在构建路径中引用它。

The app builds successfully, but upon starting on either the emulator (using 2.2) or the device (using 4.0.4), it crashes with the error:

应用程序构建成功,但在模拟器(使用 2.2)或设备(使用 4.0.4)上启动时,它崩溃并显示错误:

java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable
        at com.actionbarsherlock.view.MenuInflater$MenuState.readItem(MenuInflater.java:328)
        ...

I am not using proguard.

我没有使用混淆器。

I have tried cleaning the ActionBarSherlock project, copying the new jar into my sample project's libs, and then cleaning my sample project.

我尝试清理 ActionBarSherlock 项目,将新 jar 复制到我的示例项目的库中,然后清理我的示例项目。

My MainActivity.java is quite simple:

我的 MainActivity.java 很简单:

package com.example.lrn;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import android.os.Bundle;

public class MainActivity extends SherlockActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getSupportMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

The menu has but a single item:

菜单只有一个项目:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_settings"
        android:title="@string/menu_settings"
        android:orderInCategory="100"
        android:showAsAction="ifRoom" />
</menu>

And the AndroidManifest.xml is also just about as Eclipse created it:

AndroidManifest.xml 也与 Eclipse 创建的差不多:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.lrn"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

At this point I really have no idea what I may have missed.

在这一点上,我真的不知道我可能错过了什么。

回答by Michael Hampton

I resolved this issue myself by adding ActionBarSherlock to my Eclipse project in a different way.

我通过以不同的方式将 ActionBarSherlock 添加到我的 Eclipse 项目中自己解决了这个问题。

Instead of copying actionbarsherlock.jar into libs and adding it to the build path, I added it as a referenced project in the Android section of the project properties.

我没有将 actionbarsherlock.jar 复制到 libs 并将其添加到构建路径中,而是将其添加为项目属性的 Android 部分中的引用项目。

The app now builds and runs correctly on both the emulator and the device.

该应用程序现在可以在模拟器和设备上正确构建和运行。

enter image description here

在此处输入图片说明

回答by Sharj

If you get:

如果你得到:

 ActionBarSherlock: java.lang.NoClassDefFoundError:
         com.actionbarsherlock.R$styleable 

exception, then you can fix that by adding Sherlock theme in your manifest file.

异常,那么您可以通过在清单文件中添加 Sherlock 主题来解决该问题。

android:theme="@style/Theme.Sherlock.Light.DarkActionBar"

回答by Learn OpenGL ES

There's a problem with the latest ADT 21.1 that can cause this error to surface, even if everything else seems correct. You can fix it by downgrading to ADT 21 and the tools r21. Here's a bug report with some more detail:

最新的 ADT 21.1 存在一个问题,可能导致此错误浮出水面,即使其他一切看起来都是正确的。您可以通过降级到 ADT 21 和工具 r21 来修复它。这是一个包含更多细节的错误报告:

https://code.google.com/p/android/issues/detail?id=42686

https://code.google.com/p/android/issues/detail?id=42686

回答by user3146033

Please let your project's package name and the 3rd party lib package name as the same.

请让你的项目的包名和第 3 方的 lib 包名一样。

e.g. if the 3rd party lib package name is com.actionbarsherlock and your project's package name is com.yourproject it is of course, you will get java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable error.

例如,如果第 3 方 lib 包名称是 com.actionbarsherlock 并且您项目的包名称是 com.yourproject 它当然会出现 java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable 错误。

To use the 3rd party lib and not use reference like Michael Hampton's answer, you should follow the steps:

要使用第 3 方库而不是像迈克尔汉普顿的回答那样使用参考,您应该按照以下步骤操作:

  1. rename the package name of com.actionbarsherlock to com.yourproject( I assume that the package name of your project is com.yourproject. Click right button of the mouse on your project -> Android Tools-> Rename Application Package)

  2. copy com.actionbarsherlock/bin/xxx.jar to com.yourproject/libs

  3. copy or merge the resource from xxx.jar in the com.actionbarsherlock's res, such as values, anim, drawable and etc.

  1. 将com.actionbarsherlock的包名重命名为com.yourproject(我假设你的项目的包名是com.yourproject。在你的项目上点击鼠标右键-> Android工具->重命名应用程序包)

  2. 将 com.actionbarsherlock/bin/xxx.jar 复制到 com.yourproject/libs

  3. 复制或合并com.actionbarsherlock资源中xxx.jar中的资源,如values、anim、drawable等。

I have encountered the same problem, and use the method above thought by myself successfully. If there's more problem, please ask more. I hope all guys could settle the same problem.

我也遇到了同样的问题,用上面自己想到的方法成功了。如果有更多问题,请多问。我希望所有的人都可以解决同样的问题。

回答by huntersea

make sure ActionBarSherlock project \gen folder has R.java file

确保 ActionBarSherlock 项目 \gen 文件夹有 R.java 文件