0

我正在尝试使用 SharLock 库创建操作栏,我在我的项目中添加了 Sharlock 库。

这是我的代码,

public class MainActivity extends SherlockActivity implements ActionBar.OnNavigationListener {

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

            Button btnClick=(Button)findViewById(R.id.clickMe);
            btnClick.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    Intent intent=new Intent(MainActivity.this,ListNavigation.class);
                    startActivity(intent);
                }
            });
        }

        @Override
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {
            // TODO Auto-generated method stub
            return false;
        }

在我的清单代码中,

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.actionbar"
    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" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" android:theme="@style/Theme.Sherlock">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

一旦我使用扩展 SherlockActivity 实现 ActionBar.OnNavigationListener,我就会收到这样的错误,

11-23 12:56:48.811: ERROR/AndroidRuntime(3047): FATAL EXCEPTION: main
11-23 12:56:48.811: ERROR/AndroidRuntime(3047): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.actionbar/com.example.actionbar.MainActivity}: java.lang.ClassNotFoundException: com.example.actionbar.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.actionbar-1.apk]
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at android.os.Looper.loop(Looper.java:123)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at java.lang.reflect.Method.invokeNative(Native Method)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at java.lang.reflect.Method.invoke(Method.java:521)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at dalvik.system.NativeStart.main(Native Method)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047): Caused by: java.lang.ClassNotFoundException: com.example.actionbar.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.actionbar-1.apk]
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
11-23 12:56:48.811: ERROR/AndroidRuntime(3047):     ... 11 more
4

1 回答 1

1

logcat 声明您启动了 Activity :

com.example.acctionbar.MainActivity

acccccctionbar 中有两个 c。在您的代码中搜索此拼写并将其更改为一个 c。

于 2012-11-23T07:41:48.070 回答