Kotlin:找不到类“ java.time.LocalDateTime”

时间:2019-09-16 14:57:58

标签: android kotlin

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

class Authentication : AppCompatActivity() {
    var fireBaseAuthentication = FirebaseAuth.getInstance()

    private var mobileApi: MobileApi? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        JodaTimeAndroid.init(this)
        setContentView(R.layout.activity_authentication)
        mobileApi = MobileApi()
        buttonLogin.setOnClickListener {
            signIn(editTextEmail.text.toString(), editTextPassword.text.toString())

        }
        txtViewSignUp.setOnClickListener {
            var intent = Intent(this, Register::class.java)
            startActivity(intent)
            overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out)
        }
    }

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

    private fun signIn(email: String, password: String) {
        showMessage("Authenticating...")
        fireBaseAuthentication.signInWithEmailAndPassword(email, password).addOnCompleteListener { task ->
            if (task.isSuccessful) {
                GlobalScope.launch(Dispatchers.IO) {
                    val user = fireBaseAuthentication.currentUser?.uid?.let { mobileApi!!.apiMobileUsersGetByFireBaseIDGet(it) }//////////////////////
                    withContext(Dispatchers.Main) {
                        println(user!!.fireBaseID)
                        println(user!!.email)
                       var intent = Intent(this@Authentication, MainActivity::class.java)
                        intent.apply {
                            putExtra("id", user.fireBaseID)
                            putExtra("email", user.email)*/
                      }
                     startActivity(intent)
                    }
                }
            } else {
                showMessage("Error: ${task.exception?.message}")
            }
        }

    }

    private fun showMessage(message: String) {
        Toast.makeText(this, message, Toast.LENGTH_LONG).show()
    }

我还在AndroidManifest.xml中添加了Internet权限。我的问题是当我在手机中运行我的应用程序时,出现错误。 我尝试使用ThreeTenABP库和jodatime库,但该错误仍然存​​在java.lang.ClassNotFoundException:找不到类“ java.time.LocalDateTime”,错误描述如下

E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    Process: com.app.app, PID: 19319
    java.lang.ClassNotFoundException: Didn't find class "java.time.LocalDateTime" on path: DexPathList[[zip file "/data/app/com.app.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.app.appt-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:4708)
        at com.app.homecraft.ui.user.Authentication$signIn$1$1.invokeSuspend(Authentication.kt:88)
        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 个答案:

没有答案