gpt4 book ai didi

android - 使用 SherlockFragmentActivity 时应用崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 12:35:57 25 4
gpt4 key购买 nike

我正在使用 ABS。我的启动器 Activity 是 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

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

最佳答案

我在我的 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>

告诉我这是否解决了您的问题。

关于android - 使用 SherlockFragmentActivity 时应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19288114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com