Home > database >  After adding SplashScreen, the application crashes
After adding SplashScreen, the application crashes

Time:09-24

I'm new at Android developing and I create a new app. I tried to add a SplashScreen but my App crashed. My app shows th SplashScreen, but then it writes:"Unfortunately, your app has been stopped". This is my code

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lepetitprince">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.LePetitPrince"
    android:fullBackupContent="true"
    android:largeHeap="true">
    <activity
        android:name=".SplashActivity"
        android:exported="true"
        android:theme="@style/SplashScreenTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

SplashActivity:

package com.example.lepetitprince;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;

public class SplashActivity extends AppCompatActivity {

Handler handler;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splashscreen);
    handler = new Handler();
    handler.postDelayed(() -> {

        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    },3000);
}
}

And SplashScreenLayout. I will make it usabilty later

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/design_default_color_primary_dark"
android:orientation="vertical">

<ImageView
    android:id="@ id/imageView"
    android:layout_width="130dp"
    android:layout_height="130dp"
    android:contentDescription="@string/download_img"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@android:drawable/stat_sys_download" />
 </androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

MainActivity.java class has not been defined in your AndroidManifest file , this could be the reason for your crash

Add this to your Manifest file

  <activity
        android:name=".MainActivity"
        android:exported="true"/>
  • Related