question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CorourtineScope returns null

See original GitHub issue

When using coroutines for making network calls, I encountered that

private var viewModelJob = Job()
private val coroutineScope: CoroutineScope = CoroutineScope(viewModelJob + Dispatchers.Main)
private fun getMarsRealEstateProperties() {
    if (coroutineScope == null) {
        Log.d("TAG_TAG", "NULL")
    }
}

At first when using coroutineScope.launch {…}, it throws

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter receiver$0

Is this a bug or some problem on my side?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

9reactions
casablancapluspluscommented, Jan 12, 2020

you must create your job and coroutineScope before the init block.

0reactions
shubamuzumakicommented, Jul 6, 2020

you must create your job and coroutineScope before the init block.

It solved my problem, but can u explain what was the problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kotlin coroutine list returning null value - Stack Overflow
I would suggest using LivaData to observe data: class MyViewModel : ViewModel() { val listado: LiveData<String> = MutableLiveData<String>() ...
Read more >
CoroutineScope - Kotlin
Defines a scope for new coroutines. Every coroutine builder (like launch, async, etc.) is an extension on CoroutineScope and inherits its coroutineContext ...
Read more >
Return value from coroutines - CommonsWare
For a method that has coroutine scope that does work in the back ground, ... searchTeamEvents(“TeamName”) it still returns the empty string.
Read more >
Android Coroutine Recipes. Table of Contents - ProAndroidDev
Background job is executed via withContext function with the IO dispatcher. val uiScope = CoroutineScope(Dispatchers.Main)fun loadData() = uiScope.launch { view ...
Read more >
Kotlin Coroutine Job Lifecycle - Marco Cattaneo
Coroutine Scope : what's its lifecycle and the behavior of jobs. ... Parent Job: the parent Job of children jobs, by default is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found