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

Michael Hampton picture Michael Hampton · Jul 12, 2012 · Viewed 11.7k times · Source

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

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

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:

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.

My MainActivity.java is quite simple:

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:

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

Answer

Michael Hampton picture Michael Hampton · Jul 12, 2012

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

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.

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

enter image description here