Home > Net >  Application crashing as soon as it boots
Application crashing as soon as it boots

Time:10-15

I'm currently doing a project with other students, it consits of building an application but i don't get why the app crashes as soon as it runs.

This is my manifest

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

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.ProgPMobile"
        tools:targetApi="31">

        <!-- <activity android:name=".LogIn" />
        <activity android:name=".Register"/> -->

        <activity android:name=".SplashScreen"
            android:exported="true">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

    </application>

</manifest>

My Splashscreen class

package com.example.progpmobile;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.google.firebase.auth.FirebaseAuth;

class SplashScreen extends AppCompatActivity{
//CONNESIONE DB
FirebaseAuth firebaseAuth;
//Timer splash screen
private static int SPLASHSCREEN_TIMER =4000;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_screen);

    firebaseAuth = FirebaseAuth.getInstance();

    new Handler().postDelayed(new Runnable(){
        @Override
        public void run() {
            if(firebaseAuth.getCurrentUser() != null) {
                startActivity(new Intent(SplashScreen.this,MainActivity.class));
                finish();
            }
            else {
                startActivity(new Intent(SplashScreen.this,LogIn.class));
                finish();
            }
        }
    },SPLASHSCREEN_TIMER);

}
}

and here is my build.gradle(:app)

    plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.progpmobile"
        minSdk 28
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildFeatures{
        dataBinding true
        viewBinding true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'com.google.firebase:firebase-auth-ktx:21.0.8'

    def lifecycle_version = "2.4.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.annotation:annotation:1.2.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

I tried debbugging aand the error message is this

2022-10-14 12:08:47.657 13235-13235/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.progpmobile, PID: 13235 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.progpmobile/com.example.progpmobile.SplashScreen}: java.lang.IllegalAccessException: java.lang.Class<com.example.progpmobile.SplashScreen> is not accessible from java.lang.Class<android.app.AppComponentFactory> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3990) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8751) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135) Caused by: java.lang.IllegalAccessException: java.lang.Class<com.example.progpmobile.SplashScreen> is not accessible from java.lang.Class<android.app.AppComponentFactory> at java.lang.Class.newInstance(Native Method) at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95) at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45) at android.app.Instrumentation.newActivity(Instrumentation.java:1273) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3977) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loopOnce(Looper.java:226)  at android.os.Looper.loop(Looper.java:313)  at android.app.ActivityThread.main(ActivityThread.java:8751)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135) 

CodePudding user response:

You didn't mention MainActivity & LogIn in Manifest File inside application Tag. like below code :

<activity android:name=".LogIn" />
<activity android:name=".MainActivity " />

add access modifier before class name like

public class SplashScreen
  • Related