3

我正在使用 ABS。我的启动器活动是RegistrationActivity. 当我用 扩展它时SherlockActivity,我的应用程序运行良好。但是当我用 扩展它时SherlockFragmentActivity,我的应用程序在手机上运行时崩溃。

 package com.example.app;

 import android.content.Context; 
 import android.content.Intent; 
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.support.v4.app.FragmentManager; 
 import android.view.View;
 import android.support.v4.app.DialogFragment;
 import com.actionbarsherlock.app.SherlockFragmentActivity;

 public class RegistrationActivity extends SherlockFragmentActivity {

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         // Check if the user is already registered
         Context context = this;
         SharedPreferences settings = context.getSharedPreferences( "settings" , Context.MODE_PRIVATE);
         int isRegistered = settings.getInt( "isRegistered", 0 );

         if( isRegistered == 1 ) {
             Intent intent = new Intent(this, DashboardActivity.class);
             startActivity(intent);
         }
         else {
             setContentView(R.layout.activity_registration);
             getSupportActionBar().setDisplayHomeAsUpEnabled(true);
         }

     }

    public void pickCountry(View view) {

     }

 }

我在 MAC 上使用 AndroidStudio。

10-10 10:53:38.684    7751-7751/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.app/com.example.app.RegistrationActivity}: java.lang.ClassNotFoundException: com.example.app.RegistrationActivity
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1995)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
            at android.app.ActivityThread.access$600(ActivityThread.java:138)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:4787)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: com.example.app.RegistrationActivity
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1986)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
            at android.app.ActivityThread.access$600(ActivityThread.java:138)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:4787)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
            at dalvik.system.NativeStart.main(Native Method)

我什至有我的活动AndroidManifest.xml

    <activity
        android:name="com.example.app.RegistrationActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
4

2 回答 2

6

我在我的 Eclipse 中运行你的代码,确实,它崩溃了。但我修复它改变这个:

<activity
    android:name="com.example.app.RegistrationActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

这样:

<activity
    android:name="com.example.app.RegistrationActivity"
    android:theme="@style/Theme.Sherlock"
    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-10-13T04:47:37.907 回答
0

如果不在清单中,请在您开始活动时设置您的主题

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_Sherlock);
    super.onCreate(savedInstanceState);
    ...
}

清理/重建您的项目。

蚀:Project -> Clean

安卓工作室:Build -> Rebuild Project

蚂蚁:$ant clean debug

于 2013-10-16T13:44:07.170 回答