在启动名为Home Screen的活动时,应用程序在第36行尝试读取XML文件时崩溃,并出现以下错误:
Binary XML file line #36: Error inflating class fragment
<fragment
android:name="com.example.myName.myApp.EventsFragment"
android:id="@+id/events_frag"
android:layout_width="match_parent"
android:layout_height="464dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
第一行是第36行,它在我的主屏幕活动xml文件中定义了一个片段。下面是目前执行的堆栈跟踪。
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myName.myApp, PID: 15937
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.braedanshigley.feelbettertogether/com.example.braedanshigley.feelbettertogether.HomeScreen}: android.view.InflateException: Binary XML file line #36: Binary XML file line #36: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #36: Binary XML file line #36: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class fragment
Caused by: java.lang.RuntimeException: com.example.braedanshigley.feelbettertogether.HomeScreen@d0dbff6 must implement OnFragmentInteractionListener
at com.example.braedanshigley.feelbettertogether.EventsFragment.onAttach(EventsFragment.java:83)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1372)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.braedanshigley.feelbettertogether.HomeScreen.onCreate(HomeScreen.java:24)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
答案 0 :(得分:0)
您需要在OnFragmentInteractionListener
活动中实施HomeScreen. Java
。由于您正在遭遇崩溃,因此缺少该侦听器实现。
此日志清楚地表明:
Caused by: java.lang.RuntimeException: com.example.braedanshigley.feelbettertogether.HomeScreen@d0dbff6 must implement OnFragmentInteractionListener
答案 1 :(得分:0)
您的片段名称包是否正确? com.example.myName.myApp.EventsFragment这个必须是Fragment类顶部的那个