amar_1995

    amar_1995

    2 years ago
    I am calling suspend function to retive data from server and then insert that data inside room db. But I am getting this wierd error
    2020-01-30 20:25:18.750 21058-21058/com.amar.modularnewsapp E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.amar.modularnewsapp, PID: 21058
        java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Number.intValue()' on a null object reference
            at com.amar.modularnewsapp.repository.ArticleRepo$$loadMoreData$Continuation.invokeSuspend(Unknown Source:14)
            at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
            at kotlinx.coroutines.ResumeModeKt.resumeUninterceptedMode(ResumeMode.kt:46)
            at kotlinx.coroutines.internal.ScopeCoroutine.afterCompletionInternal(Scopes.kt:32)
            at kotlinx.coroutines.JobSupport.completeStateFinalization(JobSupport.kt:310)
            at kotlinx.coroutines.JobSupport.tryFinalizeSimpleState(JobSupport.kt:276)
            at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:807)
            at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:787)
            at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:111)
            at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
            at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
            at android.os.Handler.handleCallback(Handler.java:883)
            at android.os.Handler.dispatchMessage(Handler.java:100)
            at android.os.Looper.loop(Looper.java:214)
            at android.app.ActivityThread.main(ActivityThread.java:7356)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
    Any idea why I am getting this error
    I tried to run suspend function in both IO and Main thread. But yet facing this issue
    I am getting this error by running this code.
    withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
                internationalArticle = articleService.getTopHeadLine(token, options)
            }
    But now when I change my code to below piece of code, resolves the issue.
    runBlocking {
       launch(<http://Dispatchers.IO|Dispatchers.IO>) {
            internationalArticle = articleService.getTopHeadLine(token, options)
            println("Server data: " + internationalArticle)
        }
    }
    Any one know why ?
    Yang

    Yang

    2 years ago
    Don’t think coroutines is fully supported by the new IR compiler yet.