第一次使用时我的应用运行正常。但是当我在后台发送它很长时间并在膨胀类片段时重新打开它的显示错误。我确实google发现它是因为在没有UI的情况下膨胀片段但是我能够解决问题。 我的logcat如下
09-03 11:55:51.219: E/AndroidRuntime(23789): FATAL EXCEPTION: main
09-03 11:55:51.219: E/AndroidRuntime(23789): Process: com.hundredpercentile.vidyamandirclasses, PID: 23789
09-03 11:55:51.219: E/AndroidRuntime(23789): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hundredpercentile.vidyamandirclasses/com.hundredpercentile.vidyamandirclasses.test_engine.activity.TestSectionActivity}: android.view.InflateException: Binary XML file line #91: Error inflating class fragment
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.app.ActivityThread.access$800(ActivityThread.java:139)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.os.Handler.dispatchMessage(Handler.java:102)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.os.Looper.loop(Looper.java:136)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.app.ActivityThread.main(ActivityThread.java:5086)
09-03 11:55:51.219: E/AndroidRuntime(23789): at java.lang.reflect.Method.invoke(Native Method)
09-03 11:55:51.219: E/AndroidRuntime(23789): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
09-03 11:55:51.219: E/AndroidRuntime(23789): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
09-03 11:55:51.219: E/AndroidRuntime(23789): Caused by: android.view.InflateException: Binary XML file line #91: Error inflating class fragment
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-03 11:55:51.219: E/AndroidRuntime(23789): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.app.Activity.setContentView(Activity.java:1937)
09-03 11:55:51.219: E/AndroidRuntime(23789): at com.hundredpercentile.vidyamandirclasses.test_engine.activity.TestSectionActivity.onCreate(TestSectionActivity.java:151)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.app.Activity.performCreate(Activity.java:5248)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
09-03 11:55:51.219: E/AndroidRuntime(23789): ... 9 more
09-03 11:55:51.219: E/AndroidRuntime(23789): Caused by: java.lang.IllegalStateException: Fragment com.hundredpercentile.vidyamandirclasses.test_engine.fragment.TestEngineQuestionFragment did not create a view.
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.app.Activity.onCreateView(Activity.java:4826)
09-03 11:55:51.219: E/AndroidRuntime(23789): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
09-03 11:55:51.219: E/AndroidRuntime(23789): ... 20 more
我的活动使用XML中的类
来膨胀片段<fragment
android:id="@+id/view_test_section"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/view_header"
class="package.Fragment"
android:background="@color/white" />
答案 0 :(得分:0)
我怀疑TestEngineQuestionFragment需要的一些对象是垃圾收集的,而应用程序是背景的,在通胀期间导致异常。尝试在片段onCreateView中添加 lot 的Debug.Log语句,看看是否可以缩小它可能发生的位置。我也会密切关注片段布局中使用的任何自定义视图。
祝你好运。