Android java转成kotiln的报错笔记

1.java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {com.example.c.dpcode/com.example.c.dpcode.activity.MainActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data
        at android.app.ActivityThread.deliverResults(ActivityThread.java:5078)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:5120)
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
        at android.os.Handler.dispatchMessage(Handler.java:112)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7625)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
     Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data
        at com.example.c.dpcode.activity.MainActivity.onActivityResult(Unknown Source:8)
        at android.app.Activity.dispatchActivityResult(Activity.java:7797)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:5071)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:5120) 
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199) 
        at android.os.Handler.dispatchMessage(Handler.java:112) 
        at android.os.Looper.loop(Looper.java:216) 
        at android.app.ActivityThread.main(ActivityThread.java:7625) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) 

报错信息:是使用询问的方式去打开蓝牙引发的问题(点击允许打开蓝牙不会报错,拒绝打开蓝牙才会报错的)

val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)

开始以为是常量REQUEST_ENABLE_BT的报错的,但网上查了下资料最后发现不是这个报错的。

最后找到的原因是:

转成kotiln后是下面这个方法这样的

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent)

报错之处在于data可能为null,所以会闪退,改成

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)这样就不会闪退了

2.接口文件使用了泛型T,但在Activity中建立这个接口对象时,从java转Kotiln要修改部分信息

开始以为直接使用Objects就可以,但可能会和接口冲突。最后使用*就没事了

lateinit var userSubscriber: SubscriberOnNextListener<*>

lateinit是修饰符,作用是不用在定义的时候赋值。

你可能感兴趣的:(Android java转成kotiln的报错笔记)