我在這裏發現了幾個類似的問題,但提出的答案不適合我。錯誤從xml中膨脹類別片段
所以,錯誤的是:
08-13 14:40:10.723: E/AndroidRuntime(630): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragments/com.example.fragments.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
我的MainActivity是:
package com.example.fragments;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
我的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="horizontal" >
<fragment
android:id="@+id/listFragment"
android:layout_width="150dip"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize"
class="com.example.fragments.ListFragment" >
</fragment>
<fragment
android:id="@+id/detailFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.fragments.DetailFragment" >
</fragment>
</LinearLayout>
會很感激的任何幫助關於這問題
xx
是類com.example.fragments.ListFragment ,com.example.fragments.DetailFragment存在於你的應用程序中? – nandeesh 2012-08-13 15:14:05
親愛的nandeesh,是的,他們目前在項目文件夾中,並在包com.example.fragments – Dennis 2012-08-13 16:04:08