Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...