二进制XML文件行#8:错误膨胀类片段

时间:2013-11-21 00:41:52

标签: java android xml facebook-fql

所以我得到了这个片段,我正在初始化这个Linearlayout:

Public class EventFragment extends Fragment {
......
LinearLayout linearProgress;
.....
}

然后我创建我的观点:

@Override
    public View onCreateView(LayoutInflater inflater, 
            ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.event, 
                container, false);
        // Check for an open session
        Session session = Session.getActiveSession();
        if (session != null && session.isOpened()) {
            // Get the user's data
            ShowEventsFromFQL();

        }
        return view;
    }

正如您所见,我启动了我的方法ShowEventFromFQL:

这只是一个FQL请求,但在我执行该请求之前,我会显示我的进度条:

public void ShowEventsFromFQL(){
         // Check for an open session
        Session session = Session.getActiveSession();
        if (session != null && session.isOpened()) {

            //Progressbar active
            linearProgress = (LinearLayout) getView().findViewById(R.id.linProgress);
            linearProgress.setVisibility(View.VISIBLE);

.........

现在一切都很好。但如果我点击我的后退按钮并再次启动应用程序,我会收到此错误:

11-20 22:50:24.097: E/SpannableStringBuilder(11611): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-20 22:50:24.097: E/SpannableStringBuilder(11611): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-20 23:00:05.855: E/AndroidRuntime(11611): FATAL EXCEPTION: main
11-20 23:00:05.855: E/AndroidRuntime(11611): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.laurenswuyts.witpa/com.laurenswuyts.witpa.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.os.Looper.loop(Looper.java:137)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.app.ActivityThread.main(ActivityThread.java:4944)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at java.lang.reflect.Method.invokeNative(Native Method)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at java.lang.reflect.Method.invoke(Method.java:511)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at dalvik.system.NativeStart.main(Native Method)
11-20 23:00:05.855: E/AndroidRuntime(11611): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:318)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.app.Activity.setContentView(Activity.java:1924)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at com.laurenswuyts.witpa.MainActivity.onCreate(MainActivity.java:48)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.app.Activity.performCreate(Activity.java:5188)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2085)
11-20 23:00:05.855: E/AndroidRuntime(11611):    ... 11 more
11-20 23:00:05.855: E/AndroidRuntime(11611): Caused by: java.lang.NullPointerException
11-20 23:00:05.855: E/AndroidRuntime(11611):    at com.laurenswuyts.witpa.EventFragment.ShowEventsFromFQL(EventFragment.java:76)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at com.laurenswuyts.witpa.EventFragment.onCreateView(EventFragment.java:54)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:846)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1160)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
11-20 23:00:05.855: E/AndroidRuntime(11611):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:682)
11-20 23:00:05.855: E/AndroidRuntime(11611):    ... 21 more

EventFragment.java:76是我的ShowEventFrom FQL中// Progressbar活动后的一行

这是我的XML布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

     <LinearLayout
        android:id="@+id/linProgress"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone" >

        <ProgressBar
            android:id="@+id/spinnerProgressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:gravity="center">
        </ProgressBar>
    </LinearLayout>

    <ListView
        android:id="@+id/lvEvent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="@null"
        android:dividerHeight="0dp"/>

</RelativeLayout>

任何人都可以帮助我..

1 个答案:

答案 0 :(得分:1)

试试这个..删除onCreateView中的超级并运行它。

@Override
    public View onCreateView(LayoutInflater inflater, 
            ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.event, 
                container, false);
        // Check for an open session
        Session session = Session.getActiveSession();
        if (session != null && session.isOpened()) {
            // Get the user's data
            ShowEventsFromFQL();

        }
        return view;
    }

就像你必须在onCreateView

中使用下面一行一样
linearProgress = (LinearLayout) getView().findViewById(R.id.linProgress);

但你需要改变如下。

linearProgress = (LinearLayout) view.findViewById(R.id.linProgress);

view是此活动的父视图,因此请像上面的代码一样使用