指定为非null的参数为null.socketservice

dsf9zpds  于 2021-06-26  发布在  Java
关注(0)|答案(1)|浏览(344)

我的代码:

override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int
    {
        if (!this.isRunning)
        {
            this.isRunning = true
            this.backgroundThread?.start()
        }

        return START_NOT_STICKY
    }

错误:
指定为非空的参数为空:方法co.okex.app.global.services.backgroundservices.socketservice.onstartcommand,参数intent

android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3943)
android.app.ActivityThread.access$2300 (ActivityThread.java:218)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1832)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:145)
android.app.ActivityThread.main (ActivityThread.java:6934)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1404)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1199)
8qgya5xd

8qgya5xd1#

override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int

应该是

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int
``` `intent` 可能为空,因此必须允许接收 `null` 并检查 `null` 在使用之前。
请参阅此onstart命令

相关问题