tengo una aplicación que estoy tratando de hacer con Activities y con Fragments, para practicar, y a la hora de pasar de la pantalla principal a una secundaria, pasandole un argumento, me indica el siguiente error:
2023-01-19 09:51:57.572 2493-2493/com.example.digifragment E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.digifragment, PID: 2493
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
at com.example.digifragment.model.DigiDescriptions.hashCode(Unknown Source:2)
at java.util.AbstractList.hashCode(AbstractList.java:567)
at com.example.digifragment.model.Digi.hashCode(Unknown Source:81)
at androidx.navigation.NavBackStackEntry.hashCode(NavBackStackEntry.kt:256)
at java.util.HashMap.hash(HashMap.java:338)
at java.util.HashMap.put(HashMap.java:611)
at androidx.navigation.NavController.linkChildToParent(NavController.kt:143)
at androidx.navigation.NavController.addEntryToBackStack(NavController.kt:1918)
at androidx.navigation.NavController.addEntryToBackStack$default(NavController.kt:1813)
at androidx.navigation.NavController$navigate$4.invoke(NavController.kt:1721)
at androidx.navigation.NavController$navigate$4.invoke(NavController.kt:1719)
at androidx.navigation.NavController$NavControllerNavigatorState.push(NavController.kt:287)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:198)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:164)
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:1930)
at com.example.digifragment.view.MainFragment.onViewCreated$lambda$1(MainFragment.kt:65)
at com.example.digifragment.view.MainFragment.$r8$lambda$JIufCQZhcPs2zDthJ7cav-3d1xg(Unknown Source:0)
at com.example.digifragment.view.MainFragment$$ExternalSyntheticLambda1.onClick(Unknown Source:2)
at android.view.View.performClick(View.java:7441)
at android.view.View.performClickInternal(View.java:7418)
at android.view.View.access$3700(View.java:835)
at android.view.View$PerformClick.run(View.java:28676)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
2023-01-19 09:52:03.144 384-384/? E/BpTransactionCompletedListener: Failed to transact (-32)
2023-01-19 09:52:05.651 1401-1779/? E/cr_CronetUrlRequestContext: Exception in upload method
com.google.android.apps.gsa.shared.q.d: Error code: 656394 | null
at com.google.android.libraries.gsa.c.a.n.fZ(SourceFile:1)
at com.google.android.libraries.gsa.k.a.n.fZ(SourceFile:2)
at com.google.common.w.a.bv.run(SourceFile:6)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at com.google.android.libraries.g.ab.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
Caused by: java.util.concurrent.TimeoutException
at com.google.android.apps.gsa.shared.util.c.w.run(SourceFile:2)
at com.google.android.libraries.gsa.k.a.k.run(SourceFile:2)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.libraries.g.r.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
2023-01-19 09:52:05.651 1401-1775/? E/cr_CronetUrlRequestContext: Exception in upload method
com.google.android.apps.gsa.shared.q.d: Error code: 656394 | null
at com.google.android.libraries.gsa.c.a.n.fZ(SourceFile:1)
at com.google.android.libraries.gsa.k.a.n.fZ(SourceFile:2)
at com.google.common.w.a.bv.run(SourceFile:6)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at com.google.android.libraries.g.ab.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
Caused by: java.util.concurrent.TimeoutException
at com.google.android.apps.gsa.shared.util.c.w.run(SourceFile:2)
at com.google.android.libraries.gsa.k.a.k.run(SourceFile:2)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.libraries.g.r.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
2023-01-19 09:52:07.026 345-345/? E/[email protected]: Failed to getEnergyData
2023-01-19 09:52:21.106 1401-1775/? E/cr_CronetUrlRequestContext: Exception in upload method
com.google.android.apps.gsa.shared.q.d: Error code: 656394 | null
at com.google.android.libraries.gsa.c.a.n.fZ(SourceFile:1)
at com.google.android.libraries.gsa.k.a.n.fZ(SourceFile:2)
at com.google.common.w.a.bv.run(SourceFile:6)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at com.google.android.libraries.g.ab.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
Caused by: java.util.concurrent.TimeoutException
at com.google.android.apps.gsa.shared.util.c.w.run(SourceFile:2)
at com.google.android.libraries.gsa.k.a.k.run(SourceFile:2)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.libraries.g.r.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
2023-01-19 09:52:21.141 1401-1775/? E/cr_CronetUrlRequestContext: Exception in upload method
com.google.android.apps.gsa.shared.q.d: Error code: 656394 | null
at com.google.android.libraries.gsa.c.a.n.fZ(SourceFile:1)
at com.google.android.libraries.gsa.k.a.n.fZ(SourceFile:2)
at com.google.common.w.a.bv.run(SourceFile:6)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at com.google.android.libraries.g.ab.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
Caused by: java.util.concurrent.TimeoutException
at com.google.android.apps.gsa.shared.util.c.w.run(SourceFile:2)
at com.google.android.libraries.gsa.k.a.k.run(SourceFile:2)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.libraries.g.r.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
2023-01-19 09:52:27.738 4152-4152/? E/ActivityThread: Service com.google.pixel.exo.core.PersistentService has leaked ServiceConnection com.google.pixel.exo.core.PersistentService$1@d3a7c23 that was originally bound here
android.app.ServiceConnectionLeaked: Service com.google.pixel.exo.core.PersistentService has leaked ServiceConnection com.google.pixel.exo.core.PersistentService$1@d3a7c23 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1934)
at android.app.LoadedApk.getServiceDispatcherCommon(LoadedApk.java:1806)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1785)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1965)
at android.app.ContextImpl.bindService(ContextImpl.java:1896)
at android.content.ContextWrapper.bindService(ContextWrapper.java:810)
at com.google.pixel.exo.core.PersistentService.bindToWirecutter(PersistentService.java:131)
at com.google.pixel.exo.core.PersistentService.onStartCommand(PersistentService.java:121)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4639)
at android.app.ActivityThread.access$2000(ActivityThread.java:247)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
2023-01-19 09:52:39.926 5847-5847/? E/id.gms.unstabl: Not starting debugger since process cannot load the jdwp agent.
2023-01-19 09:52:40.940 4792-4902/? E/WakeLock: DG:service ** IS FORCE-RELEASED ON TIMEOUT **
2023-01-19 09:52:52.079 1401-1779/? E/cr_CronetUrlRequestContext: Exception in upload method
com.google.android.apps.gsa.shared.q.d: Error code: 656394 | null
at com.google.android.libraries.gsa.c.a.n.fZ(SourceFile:1)
at com.google.android.libraries.gsa.k.a.n.fZ(SourceFile:2)
at com.google.common.w.a.bv.run(SourceFile:6)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at com.google.android.libraries.g.ab.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
Caused by: java.util.concurrent.TimeoutException
at com.google.android.apps.gsa.shared.util.c.w.run(SourceFile:2)
at com.google.android.libraries.gsa.k.a.k.run(SourceFile:2)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.libraries.g.r.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
2023-01-19 09:52:52.140 1401-1775/? E/cr_CronetUrlRequestContext: Exception in upload method
com.google.android.apps.gsa.shared.q.d: Error code: 656394 | null
at com.google.android.libraries.gsa.c.a.n.fZ(SourceFile:1)
at com.google.android.libraries.gsa.k.a.n.fZ(SourceFile:2)
at com.google.common.w.a.bv.run(SourceFile:6)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at com.google.android.libraries.g.ab.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
Caused by: java.util.concurrent.TimeoutException
at com.google.android.apps.gsa.shared.util.c.w.run(SourceFile:2)
at com.google.android.libraries.gsa.k.a.k.run(SourceFile:2)
at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.libraries.g.r.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.libraries.g.n.run(SourceFile:2)
at com.google.android.libraries.g.d.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:920)
2023-01-19 09:53:11.533 1401-1401/? E/A: onError
com.google.android.apps.gsa.shared.speech.a.n: errorCode: 65561, engine: 2
at com.google.android.apps.gsa.staticplugins.di.a.e.a(SourceFile:3)
at com.google.android.apps.gsa.s3.n.gF(SourceFile:1)
at com.google.ce.g.a.f.f(SourceFile:2)
at com.google.android.apps.gsa.speech.k.a.g.d(SourceFile:21)
at com.google.android.apps.gsa.speech.k.a.g.jG(SourceFile:6)
at com.google.android.apps.gsa.s3.o.d(SourceFile:15)
at com.google.android.apps.gsa.s3.p.run(SourceFile:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.c.a.e.run(SourceFile:2)
at com.google.android.apps.gsa.shared.util.c.a.ay.run(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.ay.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
at com.google.android.apps.gsa.shared.util.c.a.h.run(SourceFile:4)
Caused by: com.google.android.apps.gsa.shared.speech.a.p: errorCode: 65586, engine: 2
at com.google.android.apps.gsa.s3.n.gF(SourceFile:1)
at com.google.ce.g.a.f.f(SourceFile:2)
at com.google.android.apps.gsa.speech.k.a.g.d(SourceFile:21)
at com.google.android.apps.gsa.speech.k.a.g.jG(SourceFile:6)
at com.google.android.apps.gsa.s3.o.d(SourceFile:15)
at com.google.android.apps.gsa.s3.p.run(SourceFile:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.c.a.e.run(SourceFile:2)
at com.google.android.apps.gsa.shared.util.c.a.ay.run(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.ay.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
at com.google.android.apps.gsa.shared.util.c.a.h.run(SourceFile:4)
Caused by: com.google.android.apps.gsa.shared.speech.a.l: errorCode: 401, engine: 2
at com.google.android.apps.gsa.assistant.shared.m.h.a(SourceFile:5)
at com.google.android.apps.gsa.s3.producers.j.gX(SourceFile:2)
at com.google.android.apps.gsa.speech.k.a.g.d(SourceFile:15)
at com.google.android.apps.gsa.speech.k.a.g.jG(SourceFile:6)
at com.google.android.apps.gsa.s3.o.d(SourceFile:15)
at com.google.android.apps.gsa.s3.p.run(SourceFile:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.c.a.e.run(SourceFile:2)
at com.google.android.apps.gsa.shared.util.c.a.ay.run(SourceFile:1)
at com.google.android.apps.gsa.shared.util.c.a.ay.run(SourceFile:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
at com.google.android.apps.gsa.shared.util.c.a.h.run(SourceFile:4)
El archivo de MainFragment al que hace referencia sería este:
private lateinit var binding: FragmentMainBinding
private val digiViewModel: DigiViewModel by viewModels()
private lateinit var navController: NavController
private lateinit var digimon: Digi
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = FragmentMainBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
navController = view.findNavController()
digiViewModel.cargarDatos()
digiViewModel.digiLiveData.observe(viewLifecycleOwner){
binding.digiName.text = it.name
binding.digimonImage.load(it.images[0].href)
binding.digimonLevels.apply {
adapter = LevelAdapter(it.levels)
layoutManager = LinearLayoutManager(context)
addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
}
binding.digimonAttributes.apply{
adapter = AttributeAdapter(it.attributes)
layoutManager = LinearLayoutManager(context)
addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
}
binding.digimonTypes.apply{
adapter = TypeAdapter(it.types)
layoutManager = LinearLayoutManager(context)
addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
}
binding.digimonFields.apply {
adapter = FieldAdapter(it.fields)
layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.HORIZONTAL))
}
digimon = digiViewModel.digiLiveData.value!!
}
binding.digimonImage.setOnClickListener {
navController.navigate(MainFragmentDirections.actionMainFragmentToDetailsFragment(digimon))
}
}
Y a la hora de hacer el gráfico de navegación le paso los argumentos de esta manera:
Cada vez que doy click en el único evento que tiene el fragment me da un error. Según parece es un error en la lambda pero no entiendo el por qué.
Después de debuggear la aplicación, puedo decir que el objeto que paso por parámetro no es null, es el objeto que quiero concretamente, el navController tampoco es null. De hecho, el único problema que llegué a encontrar modificando la pasada de parámetros es que el MainFragmentDirections debe dar algún tipo de error que desconozco completamente, ya que el resto funciona bien.