0

为什么当我从 SherlockActivity 继承时我的应用程序会崩溃?这可能是一个愚蠢的错误,但我真的想不通!只是从 Activity 继承确实有效。这是代码、布局文件、清单和 logcat 日志:

package com.p4p.joinme;

import android.os.Bundle;

import com.actionbarsherlock.app.SherlockActivity;

public class MainActivity extends SherlockActivity {

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

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="I'm a textview." />

</LinearLayout>

显现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.p4p.joinme"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />

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

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

</manifest>

错误日志:

06-07 12:03:22.613: E/ExternalAccountType(21992): Unsupported attribute readOnly

06-07 12:03:23.244: E/ExternalAccountType(21992): Unsupported attribute readOnly

06-07 12:03:25.316: E/AndroidRuntime(9285): FATAL EXCEPTION: main

06-07 12:03:25.316: E/AndroidRuntime(9285): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.p4p.joinme/com.p4p.joinme.MainActivity}: java.lang.ClassNotFoundException: com.p4p.joinme.MainActivity

06-07 12:03:25.316: E/AndroidRuntime(9285):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at android.app.ActivityThread.access$600(ActivityThread.java:139)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at android.os.Handler.dispatchMessage(Handler.java:99)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at android.os.Looper.loop(Looper.java:154)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at android.app.ActivityThread.main(ActivityThread.java:4945)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at java.lang.reflect.Method.invokeNative(Native Method)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at java.lang.reflect.Method.invoke(Method.java:511)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at dalvik.system.NativeStart.main(Native Method)

06-07 12:03:25.316: E/AndroidRuntime(9285): Caused by: java.lang.ClassNotFoundException: com.p4p.joinme.MainActivity
06-07 12:03:25.316: E/AndroidRuntime(9285):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at android.app.Instrumentation.newActivity(Instrumentation.java:1039)

06-07 12:03:25.316: E/AndroidRuntime(9285):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)

06-07 12:03:25.316: E/AndroidRuntime(9285):     ... 11 more

06-07 12:03:25.326: E/EmbeddedLogger(239): App crashed! Process: com.p4p.joinme

06-07 12:03:25.326: E/EmbeddedLogger(239): App crashed! Package: com.p4p.joinme v1 (1.0)

06-07 12:03:25.326: E/EmbeddedLogger(239): Application Label: JoinMe!

06-07 12:07:33.959: E/ExternalAccountType(21992): Unsupported attribute readOnly

06-07 12:07:34.299: E/ExternalAccountType(21992): Unsupported attribute readOnly

06-07 12:07:37.452: E/EmbeddedLogger(239): App crashed! Process: com.p4p.joinme

06-07 12:07:37.452: E/EmbeddedLogger(239): App crashed! Package: com.p4p.joinme v1 (1.0)


06-07 12:07:37.452: E/AndroidRuntime(9610): FATAL EXCEPTION: main

06-07 12:07:37.452: E/AndroidRuntime(9610): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.p4p.joinme/com.p4p.joinme.MainActivity}: java.lang.ClassNotFoundException: com.p4p.joinme.MainActivity

06-07 12:07:37.452: E/AndroidRuntime(9610):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at android.app.ActivityThread.access$600(ActivityThread.java:139)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at android.os.Handler.dispatchMessage(Handler.java:99)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at android.os.Looper.loop(Looper.java:154)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at android.app.ActivityThread.main(ActivityThread.java:4945)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at java.lang.reflect.Method.invokeNative(Native Method)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at java.lang.reflect.Method.invoke(Method.java:511)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at dalvik.system.NativeStart.main(Native Method)

06-07 12:07:37.452: E/AndroidRuntime(9610): Caused by: java.lang.ClassNotFoundException: com.p4p.joinme.MainActivity

06-07 12:07:37.452: E/AndroidRuntime(9610):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at android.app.Instrumentation.newActivity(Instrumentation.java:1039)

06-07 12:07:37.452: E/AndroidRuntime(9610):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)

06-07 12:07:37.452: E/AndroidRuntime(9610):     ... 11 more

06-07 12:07:37.472: E/EmbeddedLogger(239): Application Label: JoinMe!

06-07 12:07:38.933: E/ActivityManager(239): fail to set top app changed!
4

5 回答 5

0

使用以下代码:

<activity
            android:name="com.p4p.joinme.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

清理你的项目并运行..

于 2013-06-07T10:30:58.860 回答
0

我对外部库也有同样的问题,也许你的外部库没有导出到你的 apk,我建议你看看这个:找不到类

于 2013-06-07T10:31:38.547 回答
0

您的代码没有问题。Jst 与您的库交叉检查它是否已链接到您的项目中。交叉检查的步骤是右键单击项目 -> 属性 -> Android/java 构建路径

于 2013-06-07T10:28:01.083 回答
0

我不确定这是否与您的错误有关,但如果您想使用 Sherlock Action Bar,您需要使用他们的主题:

<application
    android:allowBackup="false"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock" >

此外,如果您刚刚更新了 ADT 插件,您可能需要检查 Java Build Path 中的 Private Libraries。

右键单击项目->属性->Java构建路径->订购和导出(选项卡)->激活Andrid Private Libraries旁边的复选框

于 2013-06-07T10:33:53.527 回答
0

You probably haven't linked the library correctly, make sure you added it to the library section in rightclick -> properies -> Android.

于 2013-06-07T10:24:48.073 回答