Итак, я только начал изучать android разработку приложений и следую примеру кода из книги (Android Ученик). Я получаю эту ошибку, когда пытаюсь запустить свое приложение. Я начинающий и не знаю, к чему это относится. Я только в первой главе книги, поэтому я мало знаю, как работает этот импорт. Вот код, который я пытаюсь запустить. Ошибка появляется в v7 в строке 4, и я не могу найти какие-либо решения для этого. Книга продолжается с этой настройкой, и я застрял в этом неспособно продолжить вдоль книги.
package com.raywenderlich.timefighter
import android.os.Bundle
import android.widget.Button
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.myapplication.R
class MainActivity : AppCompatActivity() {
private var score = 0
//VARIABLES
private lateinit var gameScoreTextView: TextView
private lateinit var timeLeftTextView: TextView
private lateinit var tapMeButton: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// connect views to variables
// 1
gameScoreTextView = findViewById(R.id.game_score_text_view)
timeLeftTextView = findViewById(R.id.time_left_text_view)
tapMeButton = findViewById(R.id.tap_me_button)
// 2
tapMeButton.setOnClickListener { incrementScore() }
}
private fun incrementScore() {
// increment score logic
score++
val newScore = "Your Score: $score"
gameScoreTextView.text = newScore
}
private fun resetGame() {
// reset game logic
}
private fun startGame() {
// start game logic
}
private fun endGame() {
// end game logic
}
}
Если я удаляю эту строку, приложение создается, но оно падает, трассировка стека показывает это
2020-04-12 00:57:14.484 10918-10918/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 10918
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/~~emAQAZ4Gvj2DAy6KoYvCRQ==/com.example.myapplication-_p61rFlmUmeJx3nvyq5Pcg==/base.apk"],nativeLibraryDirectories=[/data/app/~~emAQAZ4Gvj2DAy6KoYvCRQ==/com.example.myapplication-_p61rFlmUmeJx3nvyq5Pcg==/lib/x86, /system/lib, /system_ext/lib, /product/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3257)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3477)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2043)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7464)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myapplication.MainActivity" on path: DexPathList[[zip file "/data/app/~~emAQAZ4Gvj2DAy6KoYvCRQ==/com.example.myapplication-_p61rFlmUmeJx3nvyq5Pcg==/base.apk"],nativeLibraryDirectories=[/data/app/~~emAQAZ4Gvj2DAy6KoYvCRQ==/com.example.myapplication-_p61rFlmUmeJx3nvyq5Pcg==/lib/x86, /system/lib, /system_ext/lib, /product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:202)
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:1253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3477)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2043)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7464)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
и компилятор выдает следующую ошибку
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 10583
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/~~emAQAZ4Gvj2DAy6KoYvCRQ==/com.example.myapplication-_p61rFlmUmeJx3nvyq5Pcg==/base.apk"],nativeLibraryDirectories=[/data/app/~~emAQAZ4Gvj2DAy6KoYvCRQ==/com.example.myapplication-_p61rFlmUmeJx3nvyq5Pcg==/lib/x86, /system/lib, /system_ext/lib, /product/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3257)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3477)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2043)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7464)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myapplication.MainActivity" on path: DexPathList[[zip file "/data/app/~~emAQAZ4Gvj2DAy6KoYvCRQ==/com.example.myapplication-_p61rFlmUmeJx3nvyq5Pcg==/base.apk"],nativeLibraryDirectories=[/data/app/~~emAQAZ4Gvj2DAy6KoYvCRQ==/com.example.myapplication-_p61rFlmUmeJx3nvyq5Pcg==/lib/x86, /system/lib, /system_ext/lib, /product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:202)
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:1253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3477)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2043)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7464)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)