Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

java - Parameter specified as non-null is null.SocketService

my codes:

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

        return START_NOT_STICKY
    }

errors:

Parameter specified as non-null is null: method co.okex.app.global.services.backgroundservices.SocketService.onStartCommand, parameter 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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int

should be

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

intent may be null, so you must allow to receive null and check for null before using it.

Please refer to this onStartCommand


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...