so basically, i am trying to develop an app in android studio but it keeps crashing. I got no idea why. can som1 help?
This is the error code below:
2022-07-24 12:45:13.430 9938-9938/com.example.aviationista E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.aviationista, PID: 9938
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.aviationista/com.example.aviationista.MainActivity}: java.lang.InstantiationException: java.lang.Class<com.example.aviationista.MainActivity> cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3545)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
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:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.InstantiationException: java.lang.Class<com.example.aviationista.MainActivity> cannot be instantiated
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:3532)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
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:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
CodePudding user response:
Make sure the Activity is placed inside the Manifest file. Look here
CodePudding user response:
Open the app>manifests . You'll find a File called AndroidManifest
in between
<application
.
.<activity
android:name="com.example.<your_package_name>.ComponentInfo" />
.
>
</application>
This might have happened because you created a class and created a layout file seperately.. hemceforth create it like so right clock New> Activity > Empty Activity
That way your layout files get created and the manifest entry gets added as well automatically