Am nhận Lỗi inflating fragment error while running calling an Activity which having fragments.
tập tin XML Binary dòng # 9: Lỗi lớp lạm phát đoạn
Checklist là Hoạt động, trong đó có listview and Description fragments.
và mã xml của nó là:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<fragment class="com.uday.honeytest.CheckList$listview"
android:id="@+id/titles" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent" />
<fragment class="com.uday.honeytest.CheckList$Description"
android:id="@+id/details" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground" />
</LinearLayout>
lớp danh sách kiểm tra là:
public class CheckList extends Activity {
static int position=0;
static CheckList check;
public void onCreate(Bundle saved){
super.onCreate(saved);
setContentView(R.layout.checklist);
}
public static class listview extends ListFragment {
View mConverView;
String[] items;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
xxxxxx..
return mConverView;
}
}
tương tự như tôi có Mô tả đoạn dưới đây.
Nhưng am getting
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uday.honeytest/com.uday.honeytest.CheckList}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
lỗi tại dòng setContentView.
và mô tả lớp mảnh của tôi là: sửa đổi:
public static class Description extends Fragment {
View mConverView;
String details[];
public static Description getInstance() {
Description desc=new Description();
return desc;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
TextView textview=new TextView(getActivity());
textview.setLayoutParams(new LayoutParams(MarginLayoutParams.WRAP_CONTENT, MarginLayoutParams.WRAP_CONTENT));
return textview;
}
}
đang làm gì sai ở đây ??
Cảm ơn
Bạn thực sự nên đăng mã lớp Mô tả của mình. – RoflcoptrException
Kiểm tra mô tả của tôi fragment class edited: đó là trong CheckList Activity chỉ. – Udaykiran
Tôi đã thử ví dụ này từ đây: http://www.vogella.com/articles/Android/article.html#fragments và tôi có 2 vấn đề: - Tôi cần sử dụng 'android.support.v4.app 'và không' android.app.Fragment' vì tôi đang chạy dưới API cấp 8 (Android giới thiệu các đoạn trong Android 3.0 (API cấp 11)) - 'android: layout_marginTop ="? android: attr/actionBarSize "' trong khai báo đoạn không tương thích với API cấp 8 - xem http: // stackoverflow.com/questions/7760817/how-to-get-androidattr-actionbarsize-với-khả năng tương thích-thư viện – Paul