lingjunqi
「已注销」
2015-12-04 18:24
采纳率: 33.3%
浏览 1.9k
已结题

android中fragment的使用问题。

程序在打开的时候就报错。

这是Android Monitor上的信息:

12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: FATAL EXCEPTION: main
12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thefat.lingjunqi.enricher/com.thefat.lingjunqi.enricher.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment

问题已经解决,谢谢大家

  • 点赞
  • 收藏

5条回答 默认 最新

  • hehui1860
    小小豆豆浆 2015-12-06 07:01
    已采纳

    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: Caused by: java.lang.IllegalStateException: Fragment ReadingTitleFragment{414f5f38} not attached to Activity
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Fragment.getResources(Fragment.java:762)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.thefat.lingjunqi.enricher.ReadingTitleFragment.(ReadingTitleFragment.java:27)
    这个地方是不是就有getActivity了,应该是还没有attached到Activity中有异常

    点赞 评论
  • lingjunqi
    「已注销」 2015-12-04 18:26

    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:156)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.os.Looper.loop(Looper.java:153)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5338)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:278)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Activity.setContentView(Activity.java:1895)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.thefat.lingjunqi.enricher.MainActivity.onCreate(MainActivity.java:14)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5232)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2272)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:156)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.os.Looper.loop(Looper.java:153)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5338)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: Caused by: java.lang.IllegalStateException: Fragment ReadingTitleFragment{414f5f38} not attached to Activity
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Fragment.getResources(Fragment.java:762)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.thefat.lingjunqi.enricher.ReadingTitleFragment.(ReadingTitleFragment.java:27)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at java.lang.Class.newInstanceImpl(Native Method)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at java.lang.Class.newInstance(Class.java:1319)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Fragment.instantiate(Fragment.java:585)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Fragment.instantiate(Fragment.java:560)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Activity.onCreateView(Activity.java:4837)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:278)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Activity.setContentView(Activity.java:1895)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.thefat.lingjunqi.enricher.MainActivity.onCreate(MainActivity.java:14)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5232)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2272)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:156)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.os.Looper.loop(Looper.java:153)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5338)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    12-05 01:51:58.359 21231-21231/com.thefat.lingjunqi.enricher E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)

    这是剩下的报错信息

    点赞 评论
  • Marksinoberg
    泰 戈 尔 2015-12-04 23:39

    好像是xml文件的第六行出的问题,你检查一下binary试试,修改一下,估计就能解决了。希望能帮到你哦图片说明

    点赞 评论
  • EricFantastic
    EricFantastic 2015-12-05 00:36

    应该是reading_title_frag.xml第六行报错了,异常里写着

    点赞 评论
  • zhanggang740
    JackWaiting 2015-12-05 05:33

    你的代码报错是InflateException,跟你接收不接收到list的关系,如果是接收不到list,报错是空指针,你这里明显是View view=inflater.inflate(R.layout.reading_title_frag, container, false);这一行报错,看下你的R文件指向有没有问提,你首先要排查一下是不是你的activity有问题,从你的代码分析,你的activity有问题的概率很大。

    点赞 评论

相关推荐