java.lang.ClassNotFoundException:找不到类“ java.time.LocalDateTime”

时间:2019-06-24 09:53:31

标签: android kotlin kotlin-coroutines

我是Kotlin的新手,我想创建一个Android移动应用程序。我使用Android Studio 3.3(Android API级别28)。我用招摇的方式获取了我所有的RESTful Web服务,因此,我有了android -client生成的文件包含所有Web服务。首先,我创建了一个用于使用“电子邮件和密码”进行身份验证的android接口。在可用的Web服务中,“ apiMobileUsersGetByFireBaseIDGet”。为此,请使用Firebase ID进行身份验证。 我创建如下的kotlin类AUthentication:

class Authentication : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_authentication)
        var email = editTextEmail.text
        var password = editTextPassword.text

        FirebaseApp.initializeApp(this@Authentication)
        val auth = FirebaseAuth.getInstance()

        buttonlogin.setOnClickListener {
            auth.signInWithEmailAndPassword(email.toString(), password.toString())
                .addOnCompleteListener(this) { task ->
                    if (task.isSuccessful) {
                        println("success")
                        if (verifyAvailableNetwork(this@Authentication)) {
                            CoroutineScope(Dispatchers.IO).launch {
                                val user = MobileApi().apiMobileUsersGetByFireBaseIDGet(auth.currentUser!!.uid)
                                if (user == UsersData()) {
                                    withContext(Dispatchers.Main) {
                                        var intent = Intent(this@Authentication, MainActivity::class.java)
                                        intent.putExtra("id", auth.currentUser?.email)
                                        startActivity(intent)
                                    }
                                }
                            }
                        }
                    } else {
                        println("Error: ${task.exception?.message}")
                    }
                }


        }


    }


    fun verifyAvailableNetwork(activity: AppCompatActivity): Boolean {
        val connectivityManager = activity.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val networkInfo = connectivityManager.activeNetworkInfo
        return networkInfo != null && networkInfo.isConnected
    }

}

我还在AndroidManifest.xml中添加了Internet权限。我的问题是,当我在手机上运行我的应用程序时,出现了错误

java.lang.ClassNotFoundException: Didn't find class "java.time.LocalDateTime"  appear.Could you please tell me how can make my app functional and where's the problem, I'm really stuck.  The error description as the following :
E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    Process: com.app.homecraft, PID: 5345
    java.lang.ClassNotFoundException: Didn't find class "java.time.LocalDateTime" on path: DexPathList[[zip file "/data/app/com.app.homecraft-1/base.apk", zip file "/data/app/com.app.homecraft-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.app.homecraft-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.app.homecraft-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.app.homecraft-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.app.homecraft-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.app.homecraft-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.app.homecraft-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.app.homecraft-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.app.homecraft-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.app.homecraft-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.app.homecraft-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.app.homecraft-1/lib/arm64, /vendor/lib64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.parseType(KDeclarationContainerImpl.kt:283)
        at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.loadParameterTypes(KDeclarationContainerImpl.kt:274)
        at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.findConstructorBySignature(KDeclarationContainerImpl.kt:242)
        at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:65)
        at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:34)
        at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(ReflectProperties.java:92)
        at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:31)
        at kotlin.reflect.jvm.internal.KFunctionImpl.getCaller(KFunctionImpl.kt)
        at kotlin.reflect.jvm.ReflectJvmMapping.getJavaMethod(ReflectJvmMapping.kt:62)
        at kotlin.reflect.jvm.KCallablesJvm.setAccessible(KCallablesJvm.kt:82)
        at com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory.create(KotlinJsonAdapter.kt:206)
        at com.squareup.moshi.KotlinJsonAdapterFactory.create(KotlinJsonAdapter.kt)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:137)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:97)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:71)
        at io.swagger.client.apis.MobileApi.apiMobileUsersGetByFireBaseIDGet(MobileApi.kt:4126)
        at com.app.homecraft.Authentication$onCreate$1$1$1.invokeSuspend(Authentication.kt:43)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
        Suppressed: java.lang.ClassNotFoundException: java.time.LocalDateTime
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                ... 23 more
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

0 个答案:

没有答案