启动画面后Android应用程序崩溃

时间:2014-01-15 21:01:48

标签: android

我正在创建一个现在非常基本的应用程序,只有一个闪屏进入空白屏幕。由于某种原因,当尝试加载第二个屏幕时,应用程序在启动屏幕后直接崩溃。这之前有用,所以我不确定它的第二个屏幕是否有效,但我还没有改变到闪屏的结束。

public class Splashscreen extends Activity {
protected boolean active = true;
protected int splashtime = 5000;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.splash);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(Splashscreen.this, FullscreenActivity.class);
                startActivity(i);

                finish();
            }
        }, splashtime);



}

我认为问题是试图传递给第二堂课。第二类的代码是

public class FullscreenActivity extends Activity {

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

        setContentView(R.layout.activity_fullscreen);

    }
}

不确定问题是什么,但我可能只是错过了一些非常简单的事情

logcat的:

    01-15 20:41:25.120: D/AndroidRuntime(411): Shutting down VM
01-15 20:41:25.120: W/dalvikvm(411): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-15 20:41:25.149: E/AndroidRuntime(411): FATAL EXCEPTION: main
01-15 20:41:25.149: E/AndroidRuntime(411): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.timestables/com.example.timestables.FullscreenActivity}; have you declared this activity in your AndroidManifest.xml?
01-15 20:41:25.149: E/AndroidRuntime(411):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
01-15 20:41:25.149: E/AndroidRuntime(411):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
01-15 20:41:25.149: E/AndroidRuntime(411):  at android.app.Activity.startActivityForResult(Activity.java:2827)
01-15 20:41:25.149: E/AndroidRuntime(411):  at android.app.Activity.startActivity(Activity.java:2933)
01-15 20:41:25.149: E/AndroidRuntime(411):  at com.example.timestables.Splashscreen$1.run(Splashscreen.java:27)
01-15 20:41:25.149: E/AndroidRuntime(411):  at android.os.Handler.handleCallback(Handler.java:587)
01-15 20:41:25.149: E/AndroidRuntime(411):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-15 20:41:25.149: E/AndroidRuntime(411):  at android.os.Looper.loop(Looper.java:123)
01-15 20:41:25.149: E/AndroidRuntime(411):  at android.app.ActivityThread.main(ActivityThread.java:3647)
01-15 20:41:25.149: E/AndroidRuntime(411):  at java.lang.reflect.Method.invokeNative(Native Method)
01-15 20:41:25.149: E/AndroidRuntime(411):  at java.lang.reflect.Method.invoke(Method.java:507)
01-15 20:41:25.149: E/AndroidRuntime(411):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-15 20:41:25.149: E/AndroidRuntime(411):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-15 20:41:25.149: E/AndroidRuntime(411):  at dalvik.system.NativeStart.main(Native Method)
01-15 20:41:29.069: I/Process(411): Sending signal. PID: 411 SIG: 9

清单

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.timestables.Splashscreen"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    </activity>
    <activity
        android:name="info.androidhive.androidsplashscreentimer.FullscreenActivity"
        android:label="@string/app_name" >
    </activity>
</application>

3 个答案:

答案 0 :(得分:2)

您在Manifest中声明活动的方式是错误的(包与您的活动所在的包不同)。

更改

android:name="info.androidhive.androidsplashscreentimer.FullscreenActivity"

android:name="com.example.timestables.FullscreenActivity"

它甚至会问你是否在你的Manifest中声明了它。

答案 1 :(得分:0)

您的清单声明的活动与您开始的活动不同:

 20:41:25.149: E/AndroidRuntime(411):
 android.content.ActivityNotFoundException: Unable to find explicit
 activity class
 {com.example.timestables/com.example.timestables.FullscreenActivity};
 have you declared this activity in your AndroidManifest.xml?

查看包和您的导入。活动的名称相同,但清单中的绝对路径必须与活动匹配。

答案 2 :(得分:0)

我在许多Android项目中都遇到了同样的问题。如果清单文件正确,则此类启动应用程序中的主要罪魁祸首是开始意图行中提到的第一个意图。尝试将其更改为其他活动,并在启动屏幕后检查应用是否仍然崩溃。

    Intent intent = new Intent(Splash.this, MainActivity.class);

更改为其他活动,例如在下面给出

    Intent intent = new Intent(Splash.this, HomeActivity.class);