Logcat致命错误 - 错误扩充类碎片

时间:2016-03-27 23:47:27

标签: android android-fragments logcat

尝试在手机上运行程序时遇到错误。似乎膨胀一个类有错误。非常感谢帮助。

这个程序的我的github是: https://github.com/iilysium/BBOX

这是我的logcat:

03-27 16:44:14.339 30211-30211/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: anna.banana.bbox, PID: 30211
                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{anna.banana.bbox/anna.banana.bbox.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
                                                   at android.app.ActivityThread.access$1000(ActivityThread.java:198)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                   at android.os.Looper.loop(Looper.java:145)
                                                   at android.app.ActivityThread.main(ActivityThread.java:6837)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:372)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
                                                Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
                                                   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                   at anna.banana.bbox.MainActivity.onCreate(MainActivity.java:13)
                                                   at android.app.Activity.performCreate(Activity.java:6500)
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218) 
                                                   at android.app.ActivityThread.access$1000(ActivityThread.java:198) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:145) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:6837) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at java.lang.reflect.Method.invoke(Method.java:372) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 
                                                Caused by: java.lang.ClassCastException: android.widget.GridLayout cannot be cast to android.widget.GridView
                                                   at anna.banana.bbox.MainActivityFragment.onCreateView(MainActivityFragment.java:34)
                                                   at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
                                                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1036)
                                                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1230)
                                                   at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1332)
                                                   at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2288)
                                                   at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
                                                   at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
                                                   at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
                                                   at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:80)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:740)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:483) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:366) 
                                                   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                   at anna.banana.bbox.MainActivity.onCreate(MainActivity.java:13) 
                                                   at android.app.Activity.performCreate(Activity.java:6500) 
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120) 
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072) 
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218) 
                                                   at android.app.ActivityThread.access$1000(ActivityThread.java:198) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:145) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:6837) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at java.lang.reflect.Method.invoke(Method.java:372) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 

1 个答案:

答案 0 :(得分:0)

答案在您的日志中。

Caused by: java.lang.ClassCastException: android.widget.GridLayout cannot be cast to android.widget.GridView

您正在尝试将GridLayout转换为GridView,我检查了您的代码,这种情况发生在您的代码片段中。