Kotlin推断类型不匹配

黑鸟

我尝试使用FirebaseJobDispatcher设置JobService。

这是我的JobService:

class MyJobService : JobService() {
override fun onStartJob(job: JobParameters): Boolean {
    // Do some work here
   return false //return false if job done otherwise return true
}

override fun onStopJob(job: JobParameters): Boolean {
    return false //Should this job be retried?"
   }
}

但是,当我尝试这样设置时:

val dispatcher = FirebaseJobDispatcher(GooglePlayDriver(this))
val myJob = dispatcher.newJobBuilder()
    .setService(MyJobService::class.java) // the JobService that will be called
    .setTag("my-unique-tag")        // uniquely identifies the job
    .build()

我在Android Studio中收到此编译器错误:

类型推断失败。预期的类型不匹配:推断的类型为Class,但Class!被期待

如何在Kotlin中正确设置?

黑鸟

看来我导入了错误的JobService。

代替:

import android.app.job.JobParameters
import android.app.job.JobService

应该:

import com.firebase.jobdispatcher.JobParameters
import com.firebase.jobdispatcher.JobService

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

类型不匹配:推断的类型为T但kotlin。

Kotlin:类型推断失败。预期的类型不匹配:推断的类型为MutableList <Long?>,但预期的是MutableCollection <Long>

类型不匹配:推断的类型是但预期

类型推断失败。预期类型不匹配

错误Kotlin:类型不匹配:推断类型为T?但没想到

Kotlin - 类型不匹配:推断的类型是 Any?但布尔值是预期的

类型不匹配:推断的类型为String,但在Kotlin中应使用Charset

Kotlin:类型不匹配:推断的类型为String但应为String.Companion

错误Kotlin类型推断失败预期类型不匹配Map <MessageDestination,List <MessageSender >>

kotlin - 类型不匹配:推断类型是 MutableList<TypeA> 但 MutableList<InterfaceType> 是预期的

类型不匹配:推断的类型为NameFragment但预期使用上下文-Kotlin

类型不匹配 Kotlin

Kotlin:功能类型不匹配

Kotlin 函数类型不匹配

Kotlin类型不匹配!和?

Kotlin片段类型不匹配

kotlin 中“this”的类型不匹配

类型不匹配:推断的类型为Int,但应为Byte

Scala-推断为错误的类型,导致类型不匹配?

类型不匹配的推断类型为单位,但预期为无效

类型不匹配:推断的类型为()-> JoinColumn,但应为JoinColumn

类型不匹配:推断的类型为LoginActivity,但预期为LifecycleOwner

类型不匹配:推断的类型为Fragment,但应使用YouTubePlayerSupportFragment

Scala不匹配和Java推断的类型参数

Kotlin序列类型推断

Kotlin:“类型推断失败”

Kotlin 类型推断失败

Android(Kotlin):Observer中的类型不匹配

lambda 函数中的类型不匹配 - Kotlin