Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

415
Views
¿Por qué aparece este error en Couritunes?

2022-02-15 09:53:53.459 7750-7750/? E/ple.anotadomin: Bits desconocidos establecidos en runtime_flags: 0x8000 2022-02-15 09:53:57.317 7750-7789/com.example.anotadomina E/AndroidRuntime: EXCEPCIÓN FATAL: DefaultDispatcher-worker-1 Process: com.example. anotadomina, PID: 7750

Hola, recibo este error al intentar llamar a una diversión dentro de un couritunescope o incluso de un alcance global, no sé por qué, actualmente estoy en el tercer día tratando de resolver el error con Google sin suerte.

https://github.com/Carlosktdev/Proyectos

 java.lang.IllegalStateException: Method addObserver must be called on the main thread at androidx.lifecycle.LifecycleRegistry.enforceMainThreadIfNeeded(LifecycleRegistry.java:317) at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:172) at androidx.lifecycle.SavedStateHandleController.attachToLifecycle(SavedStateHandleController.java:49) at androidx.lifecycle.SavedStateHandleController.create(SavedStateHandleController.java:70) at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:67) at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:84) at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.create(HiltViewModelFactory.java:109) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) at androidx.lifecycle.ViewModelLazy.getValue(ViewModelProvider.kt:54) at androidx.lifecycle.ViewModelLazy.getValue(ViewModelProvider.kt:41) at com.example.anotadomina.views.MainActivity.getMainViewModel(MainActivity.kt:18) at com.example.anotadomina.views.MainActivity.access$getMainViewModel(MainActivity.kt:14) at com.example.anotadomina.views.MainActivity$add$1.invokeSuspend(MainActivity.kt:36) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Indirectamente, está tratando de llamar a addObserver en un subproceso de fondo, mientras que se suponía que debía hacerlo en el subproceso principal.

Esto se debe al acceso a su viewModel directamente desde la rutina de fondo aquí (a través de un delegado de viewModels() ):

 fun add(){ CoroutineScope(Dispatchers.IO).launch { // mainViewModel property access via delegate mainViewModel.addScore(ScoreModel(0,15,0)) } }

Una solución es obtenerlo desde fuera del launch , pero probablemente debería usar lifecycleScope en lugar de Dispatchers.IO :

 fun add(){ lifecycleScope.launch { // mainViewModel property access via delegate mainViewModel.addScore(ScoreModel(0,15,0)) } }

Lo anterior requiere la biblioteca lifecycle:lifecycle-runtime-ktx , que puede agregar a su proyecto agregando la dependencia en su build.gradle.kts :

 implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.0")
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!