简体   繁体   English

Kotlin推断出类型不匹配

[英]Kotlin inferred type mismatch

I try to setup JobService using FirebaseJobDispatcher. 我尝试使用FirebaseJobDispatcher设置JobService。

Here is my 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?"
   }
}

However when i try to setup it like this: 但是,当我尝试像这样设置它:

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()

I am getting this compiler error in Android Studio: 我在Android Studio中收到此编译器错误:

Type inference failed. 类型推断失败。 Expected type mismatch: inferred type is Class but Class! 预期类型不匹配:推断类型是Class但Class! was expected 预计

How to setup it in Kotlin correctly? 如何在Kotlin中正确设置它?

It seems that I imported wrong JobService. 好像我导入了错误的JobService。

Instead of: 代替:

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

Should be: 应该:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kotlin AndroidStudio 类型不匹配推断类型 - Kotlin AndroidStudio Type Mismatch inferred type 类型不匹配:推断类型是字符串? 但预计字符串 kotlin - Type mismatch: inferred type is String? but String was expected kotlin 类型不匹配:推断类型是String,但是在kotlin中预计会出现Charset - Type mismatch: inferred type is String but Charset was expected in kotlin 类型不匹配:推断的类型是上下文? 但希望有上下文-Kotlin - Type mismatch: inferred type is Context? but Context was expected - Kotlin Kotlin:类型不匹配:推断的类型是 Intent? 但意图是预期的 - Kotlin : Type mismatch: inferred type is Intent? but Intent was expected 类型不匹配:推断类型为 String 但预期为 Int,Kotlin - Type mismatch: inferred type is String but Int was expected , Kotlin Kotlin - 类型不匹配:推断的类型是 Unit,但 Intent 是预期的 - Kotlin - Type mismatch: inferred type is Unit but Intent was expected Kotlin类型不匹配:推断类型是View! 但TextView是预料之中的 - Kotlin Type mismatch: inferred type is View! but TextView was expected Kotlin 在我的自定义 class 数据类型上推断类型不匹配错误 - Kotlin inferred type mismatch Error on my custom class datatype 类型不匹配:推断的类型是但预期的 - Type mismatch: inferred type is but was expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM