我正在创建一个FragmentActivity
并在其onCreate
函数中使用setContentView
设置一个布局,其中包含一个Fragment
,但我收到以下错误
Fragment
和FragmentActivity
都来自android.support.v4.app
activity_main.xml是一个布局
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contact_list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:name="com.ss.contact.ContactsListFragment"/>
我检查了很多线程,但每件事情似乎都很好
1) Class name in `android:name`
2) my activity is derived from `FragmentActivity`
3) i have set my activity as a `Launcher` activity
4) have called `super.onCreate` and right after `setContentView` in `FragmentActivity`
但我仍然收到以下错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ss.home/com.ss.contact.ContactsListActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
at android.app.Activity.setContentView(Activity.java:1835)
at com.ss.contact.ContactsListActivity.onCreate(ContactsListActivity.java:51)
at android.app.Activity.performCreate(Activity.java:4470)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
... 11 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f060006
at android.content.res.Resources.getValue(Resources.java:1061)
at android.content.res.Resources.getBoolean(Resources.java:843)
at com.ss.contact.ContactsListFragment.onCreate(ContactsListFragment.java:151)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1477)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:893)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1184)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
这里是onCreateView
Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the list fragment layout
super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.contact_list_fragment, container, false);
}
答案 0 :(得分:0)
请勿在您的片段中致电super.onCreateView(inflater, container, savedInstanceState);
。