Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 288
Michael Hampton Avatar asked Jul 11 '12 23:07

Michael Hampton


2 Answers

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

like image 60
Michael Hampton Avatar answered Oct 06 '22 09:10

Michael Hampton


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.

android:theme="@style/Theme.Sherlock.Light.DarkActionBar"
like image 26
Sharj Avatar answered Oct 06 '22 08:10

Sharj