这是我第一次使用 kotlin,出于某种原因,我必须在 MainActivity 中使用 kotlin 语言。我通过Code -> Convert Java file to Kotlin file 将 MainActivity 类更改为 kotlin 文件 但是当我运行代码时,我会收到以下错误:java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ir.mohammadhf.sevenautoshow/ir.mohammadhf.sevenautoshow.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "ir.mohammadhf.sevenautoshow.MainActivity" on path: DexPathList[[zip file "/data/app/ir.mohammadhf.sevenautoshow-b4uU0l0_OCV9z_7YwD1uHg==/base.apk"],nativeLibraryDirectories=[/data/app/ir.mohammadhf.sevenautoshow-b4uU0l0_OCV9z_7YwD1uHg==/lib/x86, /data/app/ir.mohammadhf.sevenautoshow-b4uU0l0_OCV9z_7YwD1uHg==/base.apk!/lib/x86, /system/lib, /system/vendor/lib]] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2718) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.ClassNotFoundException: Didn't find class "ir.mohammadhf.sevenautoshow.MainActivity" on path: DexPathList[[zip file "/data/app/ir.mohammadhf.sevenautoshow-b4uU0l0_OCV9z_7YwD1uHg==/base.apk"]我搜索了类似的问题,但在大多数问题中,他们建议“在 Android 清单中声明活动”。但它已经为我做好了。我有什么事情要做吗?
1 回答
犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
尝试在开始时在 build.gradle 文件中应用 kotlin
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
添加回答
举报
0/150
提交
取消