简体   繁体   English

闪屏后Android App崩溃

[英]Android App crashes after splashscreen

I am creating an app which right now is really basic and only has a splash screen going into a blank screen. 我正在创建一个应用程序,该应用程序现在实际上是非常基本的,只有启动屏幕变成了空白屏幕。 for some reason the application crashes straight after the splash screen when trying to load up the second screen. 由于某些原因,当尝试加载第二个屏幕时,应用程序在启动屏幕之后立即崩溃。 this has worked before so I'm unsure if its the second screen which worked but i have not changed ot the end to the splash screen. 这之前已经起作用,所以我不确定第二个屏幕是否起作用,但是我还没有更改启动屏幕的末尾。

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



}

i think the problem is trying to pass through to the second class. 我认为问题是试图传递给第二类。 the code for the second class is 第二类的代码是

public class FullscreenActivity extends Activity {

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

        setContentView(R.layout.activity_fullscreen);

    }
}

unsure what the problem is but it's likely i'm just missing something really simple 不确定是什么问题,但是可能我只是错过了一些非常简单的东西

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

manifest 表现

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

The way you're declaring the activity in your Manifest is wrong (the package is different then the one your activity is in). 您在清单中声明活动的方式是错误的(程序包与活动所在的包不同)。

change 更改

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

to

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

It even asks you if you declared it in your Manifest. 它甚至会询问您是否在清单中声明了它。

Your manifest declares a different activity than the one you are starting: 您的清单声明的活动与开始的活动不同:

 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?

Look at the package and your imports. 查看包装和进口货。 The activities are named the same, but the absolute path in the manifest must match the activity. 活动的名称相同,但是清单中的绝对路径必须与活动匹配。

I faced same problem in many android pojects. 我在许多Android项目中都遇到了同样的问题。 If the manifest file is correct then the main culprit in this type of splash app is the first intent mentioned in start intent line. 如果清单文件正确,则此类启动应用程序中的主要罪魁祸首是开始意图行中提到的第一个意图。 Try changing it to some other activity and check if app still crashes after splash screen. 尝试将其更改为其他活动,并在启动屏幕后检查应用是否仍然崩溃。

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

change to some other activity like eg given here below 更改为其他活动,例如下面给出的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM