kotlin.TypeCastException: null cannot be cast to non-null type android.support.v7.widget

 java.lang.RuntimeException: Unable to start activity ComponentInfo{www.xl06.xyz/www.xl06.xyz.ui.MainActivity}: kotlin.TypeCastException: null cannot be cast to non-null type android.support.v7.widget.Toolbar
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2419)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2479)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5420)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: kotlin.TypeCastException: null cannot be cast to non-null type android.support.v7.widget.Toolbar
        at www.xl06.xyz.ui.MainActivity$toolbar$2.invoke(MainActivity.kt:27)
        at www.xl06.xyz.ui.MainActivity$toolbar$2.invoke(MainActivity.kt:12)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at www.xl06.xyz.ui.MainActivity.getToolbar(MainActivity.kt)
        at www.xl06.xyz.utils.ToolBarManger$DefaultImpls.MianToolBAr(ToolBarManger.kt:12)
        at www.xl06.xyz.ui.MainActivity.MianToolBAr(MainActivity.kt:12)
        at www.xl06.xyz.ui.MainActivity.initData(MainActivity.kt:21)
        at www.xl06.xyz.base.BasesActivity.onCreate(BasesActivity.kt:19)
        at android.app.Activity.performCreate(Activity.java:6267)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2372)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2479) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5420) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

我的是类型找错

override val toolbar by lazy { find<Toolbar>(R.layout.toolbar) } //错误代码
override val toolbar by lazy { find<Toolbar>(R.id.toolbar) }//正确代码

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值