Main Activity cannot start when loaded

48 views Asked by At

The app keeps crashing when I open it on an emulator. This is the activity_main.xml and the error I get.

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

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/main_nav_host"
        android:name="com.example.test_run.main.MainSessionNavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="false" />

</androidx.constraintlayout.widget.ConstraintLayout>
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.test_run.MainActivity" on path: DexPathList[[zip file "/data/app/~~f3SDJdSMUvctPuzredlmhQ==/com.example.test_run-JMnAM1A0EvaUsPTrSDaFwA==/base.apk"],nativeLibraryDirectories=[/data/app/~~f3SDJdSMUvctPuzredlmhQ==/com.example.test_run-JMnAM1A0EvaUsPTrSDaFwA==/lib/arm64, /system/lib64, /system_ext/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
2

There are 2 answers

0
iamdhavalparmar On
tools:context=".you_acitivy_class_name"

in your case maybe this is

tools:context=".MainActivity"

add this line in your ConstraintLayout like below

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".MainActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
0
pnkj On

Your should show MainActivity.java/MainActivity.kotlin and AndroidManifest.xml.