Reputation: 21
I'm trying to build use default Empty Activity file at Android Studio. (API 31)
I already search around the web, but I can't find solution for my error.
Here is error message.
2022-05-10 16:14:56.487 1708-1708/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.myapplication, PID: 1708 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.myapplication.MainActivity" on path: DexPathList[[zip file "/data/app/~~0tsfswauDN0JYmuM-yPM2g==/com.example.myapplication-1g-VIz36fStDuuRgvoCkAA==/base.apk"],nativeLibraryDirectories=[/data/app/~~0tsfswauDN0JYmuM-yPM2g==/com.example.myapplication-1g-VIz36fStDuuRgvoCkAA==/lib/x86_64, /system/lib64, /system_ext/lib64]] 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.ClassNotFoundException: Didn't find class "com.example.myapplication.MainActivity" on path: DexPathList[[zip file "/data/app/~~0tsfswauDN0JYmuM-yPM2g==/com.example.myapplication-1g-VIz36fStDuuRgvoCkAA==/base.apk"],nativeLibraryDirectories=[/data/app/~~0tsfswauDN0JYmuM-yPM2g==/com.example.myapplication-1g-VIz36fStDuuRgvoCkAA==/lib/x86_64, /system/lib64, /system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) 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)
Here is MainActivity.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Here is build.gradle
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.myapplication"
minSdk 31
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Any one have some hint?
Upvotes: 2
Views: 2488
Reputation: 41
I think the problem might be in AndroidManifest.xml, check packageName value in the manifest and check if the activities path is correctly opening the desired activity. and you need to check and add all your activity classes there.
Upvotes: -1
Reputation: 716
I believe you are missing to apply a plugin in your module gradle file.
Try to add this: id 'org.jetbrains.kotlin.android'
Upvotes: -1