猿问

((AppCompatActivity) getActivity()).setSupportActionBar(toolbar)报错

  Process: com.nsisoft.charmcampus.charmcampus, PID: 2835

                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nsisoft.charmcampus.charmcampus/com.nsisoft.charmcampus.charmcampus.MainActivity}: java.lang.ClassCastException: com.nsisoft.charmcampus.charmcampus.MainActivity cannot be cast to android.support.v7.app.AppCompatActivity

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

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

                      at android.app.ActivityThread.-wrap12(ActivityThread.java)

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

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

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

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

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

                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)

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

                   Caused by: java.lang.ClassCastException: com.nsisoft.charmcampus.charmcampus.MainActivity cannot be cast to android.support.v7.app.AppCompatActivity

                      at com.nsisoft.charmcampus.charmcampus.Auditorium.onCreateView(Auditorium.java:73)

                      at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)

                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)

                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)

                      at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)

                      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1677)

                      at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)

                      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:604)

                      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1248)

                      at android.app.Activity.performStart(Activity.java:6681)

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

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

                      at android.app.ActivityThread.-wrap12(ActivityThread.java) 

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

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

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

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

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

                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 

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


起个名字什么的果然不在行呢
浏览 2061回答 1
1回答

一条小咸鱼

你用的第三方库的MainActivity不能强制转换为AppCompactActivity
随时随地看视频慕课网APP

相关分类

Android
我要回答