Home > Blockchain >  com.chargeatfriends.android.ui.reserve.ReserveFragment: calling Fragment constructor caused an excep
com.chargeatfriends.android.ui.reserve.ReserveFragment: calling Fragment constructor caused an excep

Time:09-15

I am developing new and when I run project I am getting following exception

 E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.chargeatfriends.android, PID: 31595
        androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.chargeatfriends.android.ui.reserve.ReserveFragment: calling Fragment constructor caused an exception
           com.chargeatfriends.android.ui.map.MapFragment$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
            at android.view.View.performClick(View.java:7870)
            at android.widget.TextView.performClick(TextView.java:14970)
            at android.view.View.performClickInternal(View.java:7839)
            at android.view.View.access$3600(View.java:886)
            at android.view.View$PerformClick.run(View.java:29363)
            at android.os.Handler.handleCallback(Handler.java:883)
            at android.os.Handler.dispatchMessage(Handler.java:100)
            at android.os.Looper.loop(Looper.java:237)
            at android.app.ActivityThread.main(ActivityThread.java:7948)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
         Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.newInstance0(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
            at androidx.fragment.app.Fragment.instantiate(Fragment.java:615)
            at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57) 
            at androidx.fragment.app.FragmentManager$2.instantiate(FragmentManager.java:448) 
            at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:190) 
            at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:162) 
            at androidx.navigation.NavController.navigateInternal(NavController.kt:260) 
            at androidx.navigation.NavController.navigate(NavController.kt:1719) 
            at androidx.navigation.NavController.navigate(NavController.kt:1545) 
            at androidx.navigation.NavController.navigate(NavController.kt:1472) 
            at androidx.navigation.NavController.navigate(NavController.kt:1454) 
            at androidx.navigation.NavController.navigate(NavController.kt:1437) 
            at com.chargeatfriends.android.ui.map.MapFragment.clickListener$lambda-0(MapFragment.kt:176) 
            at com.chargeatfriends.android.ui.map.MapFragment.$r8$lambda$f_HcQmFOF4yHY3eWCzm1TTIl2BA(Unknown Source:0) 
            at com.chargeatfriends.android.ui.map.MapFragment$$ExternalSyntheticLambda0.onClick(Unknown Source:2) 
            at android.view.View.performClick(View.java:7870) 
            at android.widget.TextView.performClick(TextView.java:14970) 
           
         Caused by: kotlin.UninitializedPropertyAccessException: lateinit property sharedPref has not been initialized
            at com.chargeatfriends.android.ui.reserve.ReserveFragment.getSharedPref(ReserveFragment.kt:61)
            at com.chargeatfriends.android.ui.reserve.ReserveFragment.<init>(ReserveFragment.kt:97)
            at java.lang.reflect.Constructor.newInstance0(Native Method) 
            at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
            at androidx.fragment.app.Fragment.instantiate(Fragment.java:615) 
            at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57) 
            at androidx.fragment.app.FragmentManager$2.instantiate(FragmentManager.java:448) 
            at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:190) 
            at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:162) 
            at androidx.navigation.NavController.navigateInternal(NavController.kt:260) 
            at androidx.navigation.NavController.navigate(NavController.kt:1719) 
            at androidx.navigation.NavController.navigate(NavController.kt:1545) 
            at androidx.navigation.NavController.navigate(NavController.kt:1472) 
            at androidx.navigation.NavController.navigate(NavController.kt:1454) 
            at androidx.navigation.NavController.navigate(NavController.kt:1437) 
            at com.chargeatfriends.android.ui.map.MapFragment.clickListener$lambda-0(MapFragment.kt:176) 
            at com.chargeatfriends.android.ui.map.MapFragment.$r8$lambda$f_HcQmFOF4yHY3eWCzm1TTIl2BA(Unknown Source:0) 
            at com.chargeatfriends.android.ui.map.MapFragment$

$ExternalSyntheticLambda0.onClick(Unknown Source:2)

below my ReserveFragment.kt code huge thats why shared as gist https://gist.github.com/kyodgorbek/b78a0fa14f949baf9209b8ff5914aa02

below my MapFragment.kt when I click button I am getting exception above

val clickListener = View.OnClickListener { view ->

    when (view.getId()) {
        R.id.gotoBookingButton -> {
            sharedPref.CurrentChargePoint = CurrentChargePoint

            if (sharedPref.token.length > 0) {
                Log.d("@@@@@@@", "${sharedPref.token}: ")
                sharedPref.isAdhocBooking = false
                findNavController().navigate(R.id.navigation_reserve) // in this line


            } else {
                findNavController().navigate(R.id.navigation_settings_login)
            }
        }
        R.id.mapView -> {
            StationInfo.isVisible = false
        }
        R.id.qrButton -> {
            findNavController().navigate(R.id.activity_qr)
        }
    }
}

below my SharedPref.kt class where I am using SharedPreferences

below my ServerModule and SharedPref.kt class https://gist.github.com/kyodgorbek/84f77dfd49a21066339053d5c6118883

what I have tried I tried following calling Fragment constructor caused an exception, kotlin?

all stackoverflow answers with simular problem and invalidate cache restart and debugged it as well not success any advices greatly appreciated

CodePudding user response:

the problem is in this variable

@Inject
lateinit var sharedPref:SharedPref

you are using it in this line

var EndTime: LocalTime = LocalTime.now().plusSeconds(3600   sharedPref.defaultChargeTime)

check your dependency module if you are providing SharedPref class

  • Related