Android错误在layout-large中膨胀类片段

时间:2013-01-26 13:29:24

标签: android android-layout

您好我正在创建一个使用TabActivity的Android应用程序并且有5个标签,当单击标签时,每个标签都有一个FragmentActivity类FragmentActivity加载一个片段,我可以用另一个我用过的片段替换片段这种方法,因为我正在创建一个应该类似于iPhone应用程序的应用程序。我有两个布局文件夹布局用于普通手机和布局 - 大型平板电脑。这个应用程序工作正常,除了说到平板电脑布局,我在onCreateView膨胀布局时得到一个错误膨胀类片段。 layout-large xml文件具有两个窗格布局

这是FragmentActivity的代码

    public class ManageTab3 extends FragmentActivity {
     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.fragmentstackctivity);

            // add initial fragment, do not add to back stack, no transition animation
            addFragment(new MoreFragment(), false, FragmentTransaction.TRANSIT_NONE);

        }
      void addFragment(Fragment fragment, boolean addToBackStack, int transition) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.simple_fragment, fragment);
            ft.setTransition(transition);
            if (addToBackStack)
                ft.addToBackStack(null);
            ft.commit();
        }

}

这里是要添加的片段

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle 
                      savedInstanceState) {
 View fragmentView = inflater.inflate(R.layout.more, container, false); 
 Button button1 = (Button) fragmentView.findViewById(R.id.button_abbreviations); 
  button1.setOnClickListener(new OnClickListener(){ public void onClick(View v){ 
      addAbbrevs();
  }}
  );
  Button button2 = (Button) fragmentView.findViewById(R.id.button_info); 
  button2.setOnClickListener(new OnClickListener(){ public void onClick(View v){ 
      addInfo();
  }}
  );
  Button button3 = (Button) fragmentView.findViewById(R.id.button_help); 
  button3.setOnClickListener(new OnClickListener(){ public void onClick(View v){ 
      addHelp();
  }}
  );
  Button button4 = (Button) fragmentView.findViewById(R.id.button_about); 
  button4.setOnClickListener(new OnClickListener(){ public void onClick(View v){ 
      addAbout();
  }}
  );
    return fragmentView;

}

这是布局more.xml的

 <?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="match_parent"
    android:orientation="vertical" 
    android:gravity="center_vertical|center_horizontal"
    android:background="#F2F2F2">
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/title"
    android:layout_width="match_parent"
    android:layout_height="35dip"
    android:layout_weight="1"
   android:orientation="horizontal" 
  >
     <TextView android:id="@+id/textt" 
    android:layout_width="match_parent"
    android:layout_height="40dip"
    android:text="@string/more"
    android:textSize="15dip"
    android:gravity="center|center_vertical"
    android:textColor="#191997"/>
  </LinearLayout>
   <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="25"
   android:layout_marginTop="50dp"
   android:orientation="vertical" 
  >
     <Button
               android:id="@+id/button_abbreviations"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="@string/abbreviations"
               android:textColor="#191997"
               android:background="@drawable/btn_background"/>   
     <Button
               android:id="@+id/button_info"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="@string/info"
               android:textColor="#191997"
               android:background="@drawable/btn_background"/>
      <Button
               android:id="@+id/button_help"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="@string/help"
               android:textColor="#191997"
               android:background="@drawable/btn_background"/>
     <Button
               android:id="@+id/button_about"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="@string/about"
               android:textColor="#191997"
               android:background="@drawable/btn_background"/>
     </LinearLayout>
   </LinearLayout>

这里是layout-large more.xml的xml文件

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment android:name="babla.dict.MoreFragment"
              android:id="@+id/more_fragment"
              android:layout_weight="1"
              android:layout_width="0dp"
              android:layout_height="match_parent" />

    <fragment android:name="babla.dict.DetailsFragment"
              android:id="@+id/details_fragment"
              android:layout_weight="2"
              android:layout_width="0dp"
              android:layout_height="match_parent" />

</LinearLayout>

这是logcat错误消息

    01-26 20:42:49.713: E/AndroidRuntime(572): FATAL EXCEPTION: main
01-26 20:42:49.713: E/AndroidRuntime(572): java.lang.RuntimeException: Unable to start activity ComponentInfo{babla.dict/babla.dict.MultiLingualDictionaryActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{babla.dict/babla.dict.ManageTab3}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.os.Looper.loop(Looper.java:137)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.ActivityThread.main(ActivityThread.java:4424)
01-26 20:42:49.713: E/AndroidRuntime(572):  at java.lang.reflect.Method.invokeNative(Native Method)
01-26 20:42:49.713: E/AndroidRuntime(572):  at java.lang.reflect.Method.invoke(Method.java:511)
01-26 20:42:49.713: E/AndroidRuntime(572):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-26 20:42:49.713: E/AndroidRuntime(572):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-26 20:42:49.713: E/AndroidRuntime(572):  at dalvik.system.NativeStart.main(Native Method)
01-26 20:42:49.713: E/AndroidRuntime(572): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{babla.dict/babla.dict.ManageTab3}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.ActivityThread.startActivityNow(ActivityThread.java:1797)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:682)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.widget.TabHost.setCurrentTab(TabHost.java:346)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.widget.TabHost.addTab(TabHost.java:236)
01-26 20:42:49.713: E/AndroidRuntime(572):  at babla.dict.MultiLingualDictionaryActivity.onCreate(MultiLingualDictionaryActivity.java:30)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.Activity.performCreate(Activity.java:4465)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
01-26 20:42:49.713: E/AndroidRuntime(572):  ... 11 more
01-26 20:42:49.713: E/AndroidRuntime(572): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-26 20:42:49.713: E/AndroidRuntime(572):  at babla.dict.MoreFragment.onCreateView(MoreFragment.java:21)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-26 20:42:49.713: E/AndroidRuntime(572):  at babla.dict.MoreFragment.onCreateView(MoreFragment.java:21)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.Activity.performStart(Activity.java:4475)
01-26 20:42:49.713: E/AndroidRuntime(572):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929)
01-26 20:42:49.713: E/AndroidRuntime(572):  ... 21 more
01-26 20:42:49.713: E/AndroidRuntime(572): Caused by: java.lang.Ill

请帮助

0 个答案:

没有答案