FragmentLayout崩溃的问题,从来没有工作过

时间:2011-11-23 17:24:20

标签: java android android-layout android-fragments

EDIT2: 将源更新为当前快照。问题仍然存在! (也因审查名称而改变,因为它引起了一些混乱,这就是我的错,我应该更好地选择这些词)


编辑: 包名称已被修改以保护NDA。它实际上不是com.private.fragment。请跟我一起假设所有包装名称都完好无损且工作正常!感谢

我主要是为Gingerbread构建,我正在尝试找出这个Fragment的东西(我正在使用v13兼容包,如果我错了就纠正我只是v4兼容包的更新版本老实说,我只是想不通。事实上我得到了

android.view.InflateException: Binary XML file line #45: Error inflating class fragment

问题。 我有一个main.xml布局

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    style="@style/MainPage"
    android:orientation="vertical" >


    <LinearLayout
        android:id="@+id/Header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


        <ImageView
            android:id="@+id/ImageView01"
            android:layout_width="match_parent"
            android:layout_height="42sp"
            android:scaleType="fitXY"
            android:src="@drawable/top_header" />

    </LinearLayout>



    <LinearLayout
        android:id="@+id/SubHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="28sp"
            android:scaleType="fitXY"
            android:src="@drawable/top_sub_header" />

    </LinearLayout>

    <fragment
        android:id="@+id/fragment1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.private.thisishidden.IconList" >
        </fragment>

</LinearLayout>

我有我的主要FragmentActivity

package com.private.thisishidden;

import android.app.Activity;
import android.os.Bundle;

public class ThisIsHiddenActivity extends Activity {
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

然后我在可分解的视图布局xml文件中有一个图标列表

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    style="@style/MainPage"
    android:orientation="vertical" >


    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">


        <LinearLayout
            android:id="@+id/Scollables"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="10sp"
            android:orientation="vertical" >


            <TableLayout
                android:id="@+id/IconLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal" >

                <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="10sp" >

                    <LinearLayout
                        android:id="@+id/linearLayout1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView2"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_search" />

                        <TextView
                            android:id="@+id/textView1"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="NEAR ME" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/linearLayout2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView3"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_4" />

                        <TextView
                            android:id="@+id/textView2"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="LODGING" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/linearLayout3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView4"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_1" />

                        <TextView
                            android:id="@+id/textView3"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="ATTRACTIONS" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/linearLayout4"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView5"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_events" />

                        <TextView
                            android:id="@+id/textView4"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="EVENTS" />
                    </LinearLayout>
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="10sp" >

                    <LinearLayout
                        android:id="@+id/linearLayout5"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView6"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_7" />

                        <TextView
                            android:id="@+id/textView5"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="WELLNESS" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/linearLayout6"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView7"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_6" />

                        <TextView
                            android:id="@+id/textView6"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="FOOD" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/linearLayout7"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView8"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_8" />

                        <TextView
                            android:id="@+id/textView7"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="SHOPPING" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/linearLayout8"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView9"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_2" />

                        <TextView
                            android:id="@+id/textView8"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="PLACES" />
                    </LinearLayout>
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="10sp" >

                    <LinearLayout
                        android:id="@+id/linearLayout9"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView10"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_9" />

                        <TextView
                            android:id="@+id/textView9"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="CIRCLE" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/linearLayout10"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView11"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_3" />

                        <TextView
                            android:id="@+id/textView10"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="RECREATION" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/linearLayout11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView12"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_fav" />

                        <TextView
                            android:id="@+id/textView11"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="FAVOURITES" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/linearLayout12"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="3sp"
                        android:clickable="true"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/imageView13"
                            android:layout_width="65sp"
                            android:layout_height="55sp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="4sp"
                            android:src="@drawable/cat_5" />

                        <TextView
                            android:id="@+id/textView12"
                            style="@style/MainPage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:text="INFO" />
                    </LinearLayout>
                </TableRow>
            </TableLayout>



            <ImageView
                android:id="@+id/imageView14"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="35sp"
                android:src="@drawable/videoinfo" />

        </LinearLayout>
    </ScrollView>
</LinearLayout>

然后当然是main.xml中定义的相应类

package com.private.thisishidden;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class IconList extends Fragment {

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // inflate layout
        return inflater.inflate(R.layout.icon_view, container, false);
    }

}

我仔细查看了所有的例子,老实说这只是最后一个不起作用的版本,此刻我的智慧结束了。 因此,如果有人可以帮我指出正确的方向让片段工作,那就太棒了。

(显然上面的错误发生在应用程序启动的那一刻)

请帮助!

编辑2:不确定这将有多大帮助,但继承LogCat输出

11-24 10:49:09.501: W/ActivityThread(6998): Application com.private.thisishidden is waiting for the debugger on port 8100...
11-24 10:49:09.521: I/System.out(6998): Sending WAIT chunk
11-24 10:49:09.551: I/dalvikvm(6998): Debugger is active
11-24 10:49:09.722: I/System.out(6998): Debugger has connected
11-24 10:49:09.722: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:09.922: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:10.122: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:10.322: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:10.522: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:10.723: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:10.923: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:11.123: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:11.323: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:11.523: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:11.734: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:11.934: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:12.134: I/System.out(6998): waiting for debugger to settle...
11-24 10:49:12.334: I/System.out(6998): debugger has settled (1429)
11-24 10:49:12.464: D/dalvikvm(6998): GC_EXTERNAL_ALLOC freed 44K, 50% free 2715K/5379K, external 0K/0K, paused 37ms
11-24 10:51:51.810: I/dalvikvm(7311): Debugger is active
11-24 10:51:51.980: I/System.out(7311): Debugger has connected
11-24 10:51:51.980: I/System.out(7311): waiting for debugger to settle...
11-24 10:51:52.180: I/System.out(7311): waiting for debugger to settle...
11-24 10:51:52.390: I/System.out(7311): waiting for debugger to settle...
11-24 10:51:52.590: I/System.out(7311): waiting for debugger to settle...
11-24 10:51:52.791: I/System.out(7311): waiting for debugger to settle...
11-24 10:51:52.991: I/System.out(7311): waiting for debugger to settle...
11-24 10:51:53.191: I/System.out(7311): waiting for debugger to settle...
11-24 10:51:53.381: I/System.out(7311): waiting for debugger to settle...
11-24 10:51:53.591: I/System.out(7311): waiting for debugger to settle...
11-24 10:51:53.792: I/System.out(7311): debugger has settled (1431)
11-24 10:51:53.952: D/dalvikvm(7311): GC_EXTERNAL_ALLOC freed 47K, 50% free 2715K/5379K, external 0K/0K, paused 29ms
11-24 10:52:13.881: D/AndroidRuntime(7311): Shutting down VM
11-24 10:52:13.881: W/dalvikvm(7311): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
11-24 10:52:13.961: E/AndroidRuntime(7311): FATAL EXCEPTION: main
11-24 10:52:13.961: E/AndroidRuntime(7311): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.private.thisishidden/com.private.thisishidden.thisishiddenActivity}: android.view.InflateException: Binary XML file line #45: Error inflating class fragment
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.app.ActivityThread.access$1500(ActivityThread.java:132)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.os.Looper.loop(Looper.java:143)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.app.ActivityThread.main(ActivityThread.java:4196)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at java.lang.reflect.Method.invokeNative(Native Method)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at java.lang.reflect.Method.invoke(Method.java:507)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at dalvik.system.NativeStart.main(Native Method)
11-24 10:52:13.961: E/AndroidRuntime(7311): Caused by: android.view.InflateException: Binary XML file line #45: Error inflating class fragment
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:224)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.app.Activity.setContentView(Activity.java:1702)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at com.private.thisishidden.thisishiddenActivity.onCreate(ThisIsHiddenActivity.java:12)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
11-24 10:52:13.961: E/AndroidRuntime(7311):     ... 11 more
11-24 10:52:13.961: E/AndroidRuntime(7311): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.private.thisishidden-2.apk]
11-24 10:52:13.961: E/AndroidRuntime(7311):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.view.LayoutInflater.createView(LayoutInflater.java:471)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
11-24 10:52:13.961: E/AndroidRuntime(7311):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
11-24 10:52:13.961: E/AndroidRuntime(7311):     ... 20 more

2 个答案:

答案 0 :(得分:2)

当您使用compat lib时,您的类需要扩展FragmentActivity而不是Activity

编辑并在FragmentActivity重命名您的课程,因为这是compat lib使用的名称。

答案 1 :(得分:0)

在main.xml中将android:name="com.private.fragment.IconList"更改为class="com.private.fragment.IconList"

编辑:他正在使用compat库,所以 不能使用android:name ! edit2:显然它在sdk 15中工作