Android studio运行时闪退,请问怎么解决?

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admin.study/com.example.admin.study.NoteActivity}: java.lang.ClassCastException: android.support.design.widget.FloatingActionButton cannot be cast to android.widget.Button

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4060)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4247)

at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)

at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)

at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613)

at android.os.Handler.dispatchMessage(Handler.java:110)

at android.os.Looper.loop(Looper.java:219)

at android.app.ActivityThread.main(ActivityThread.java:8668)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

Caused by: java.lang.ClassCastException: android.support.design.widget.FloatingActionButton cannot be cast to android.widget.Button

at com.example.admin.study.NoteActivity.init(NoteActivity.java:45)

at com.example.admin.study.NoteActivity.onCreate(NoteActivity.java:39)

at android.app.Activity.performCreate(Activity.java:8214)

at android.app.Activity.performCreate(Activity.java:8202)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4033)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4247) 

at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 

at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 

at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613) 

at android.os.Handler.dispatchMessage(Handler.java:110) 

at android.os.Looper.loop(Looper.java:219) 

at android.app.ActivityThread.main(ActivityThread.java:8668) 

at java.lang.reflect.Method.invoke(Native Method) 

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)


回答:

报错信息很清楚了:

FloatingActionButton类不能转换为Button

以上是 Android studio运行时闪退,请问怎么解决? 的全部内容, 来源链接: utcz.com/p/944904.html

回到顶部