#15:错误膨胀类碎片

时间:2013-07-07 04:23:53

标签: android android-fragments android-fragmentactivity

我正在使用Fragment,但我得错了。这段代码工作3天前,我不会改变任何东西(我猜)但它不起作用。我该如何解决?

当我调用setContentView(R.layout.main)时,我看到了Log.d;在My Fragment活动中,它崩溃了。为什么这样?

我正在使用v4.app.Fragment,

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

我的xml文件和第二个片段等于15行;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

    <fragment 
            android:name="com.ex.zzigez.Home"
            android:id="@+id/home"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    <fragment 
            android:name="com.ex.zzigez.Prj"
            android:id="@+id/prj"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
</LinearLayout>

My FragmentActivity

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.widget.TextView;

public class Main extends FragmentActivity {

    private UiLifecycleHelper uiHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Log.d("deneme","Main");
        uiHelper = new UiLifecycleHelper(this, callback);
        uiHelper.onCreate(savedInstanceState);

        init();
        for (int i = 0; i < fragments.length; i++) {
            fragmentTransaction.hide(fragments[i]);
        }
        fragmentTransaction.commit();
        Log.d("deneme", "1");
        Log.d("deneme", "OnCreate Starts and All Fragments hidden!");

    }
private void init(){
        Log.d("deneme", "11");
        tv1 = (TextView) findViewById(R.id.textView1);
        fragmentManager = getSupportFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        fragments[HOME] = fragmentManager.findFragmentById(R.id.home);
        fragments[PRJ] = fragmentManager.findFragmentById(R.id.prj);
    }

我的Prj.class

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Prj extends Fragment{

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.prj, container, false);
        tv2 = (TextView) v.findViewById(R.id.textView2);

        Log.d("deneme", "PRJ.javadayız");
        Session session = Session.getActiveSession();
        if(session.isOpened()){
            makeRequest(session);
            Log.d("deneme", "PRJ session açıkk");

        }
        return v;

    }

我的LogCat

07-07 07:09:03.609: E/AndroidRuntime(30490): FATAL EXCEPTION: main
07-07 07:09:03.609: E/AndroidRuntime(30490): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.zzigez/com.ex.zzigez.Main}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.os.Looper.loop(Looper.java:137)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.app.ActivityThread.main(ActivityThread.java:4898)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at java.lang.reflect.Method.invokeNative(Native Method)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at java.lang.reflect.Method.invoke(Method.java:511)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at dalvik.system.NativeStart.main(Native Method)
07-07 07:09:03.609: E/AndroidRuntime(30490): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.app.Activity.setContentView(Activity.java:1924)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at com.ex.zzigez.Main.onCreate(Main.java:24)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.app.Activity.performCreate(Activity.java:5206)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
07-07 07:09:03.609: E/AndroidRuntime(30490):    ... 11 more
07-07 07:09:03.609: E/AndroidRuntime(30490): Caused by: java.lang.NullPointerException
07-07 07:09:03.609: E/AndroidRuntime(30490):    at com.ex.zzigez.Prj.onCreateView(Prj.java:28)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)
07-07 07:09:03.609: E/AndroidRuntime(30490):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
07-07 07:09:03.609: E/AndroidRuntime(30490):    ... 21 more

0 个答案:

没有答案