1

I'm new in Kotlin, i want to create an android mobile app.I use Android studio 3.3,the Android API level 28. I have used a swagger to get all my RESTful web service, thus, i have the android-client-generated the file that contains all the web service. As a start, I created an android interface for authentication with Email and Password". Among the web service available, "apiMobileUsersGetByFireBaseIDGet". This Ws, use the firebase Id to authenticate. I create a kotlin class AUthentication as the following :

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
    }

}

i added alse the internet permission in the AndroidManifest.xml. My problem is when i run my app in my mobile phone, an error

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
MimiSoft
  • 41
  • 4
  • 10
  • Possible duplicate of [cannot resolve symbol 'java.time.LocalDate' error in android studio](https://stackoverflow.com/questions/28745205/cannot-resolve-symbol-java-time-localdate-error-in-android-studio) – Ashish Jun 24 '19 at 09:56
  • It seems a bug in "com.squareup.moshi.Moshi" Library. Why do you use a 3rd party library instead of the built-in/included one? Read a JSON it's already easy without using a 3rd library... – emandt Jun 24 '19 at 09:57
  • when i generate the file from swagger,that contains an object Serializer.kt as the following : object Serializer { @JvmStatic val moshi: Moshi = Moshi.Builder() .add(KotlinJsonAdapterFactory()) .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe()) .build() } that's why i use the Moshi library – MimiSoft Jun 24 '19 at 10:01
  • LocalDateTime is not on the jvm used in Android. – Xavier Bouclet Jun 24 '19 at 14:16
  • I found in the file generated by swagger an object Serializer that use moshi library,and when i click in Date::class.java, which is a class Java , the following lines : import sun.util.calendar.BaseCalendar; import sun.util.calendar.CalendarDate; import sun.util.calendar.CalendarSystem; import sun.util.calendar.CalendarUtils; import sun.util.calendar.Era; import sun.util.calendar.Gregorian; gives an error, "Cannot resolve symbol" , how can i correct it – MimiSoft Jun 24 '19 at 15:29

0 Answers0