這是我第一次使用 kotlin,出于某種原因,我必須在 MainActivity 中使用 kotlin 語(yǔ)言。我通過(guò)Code -> Convert Java file to Kotlin file 將 MainActivity 類(lèi)更改為 kotlin 文件 但是當(dāng)我運(yùn)行代碼時(shí),我會(huì)收到以下錯(cuò)誤: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"]我搜索了類(lèi)似的問(wèn)題,但在大多數(shù)問(wèn)題中,他們建議“在 Android 清單中聲明活動(dòng)”。但它已經(jīng)為我做好了。我有什么事情要做嗎?
1 回答

犯罪嫌疑人X
TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
嘗試在開(kāi)始時(shí)在 build.gradle 文件中應(yīng)用 kotlin
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
添加回答
舉報(bào)
0/150
提交
取消