用抽屉导航错误类android 2.2

时间:2013-07-22 13:37:41

标签: android fragment android-inflate

我在我的应用中使用DrawerNavigator。 我创建了一个Android应用程序,它与android 4.2完美配合,但当我尝试在Android 2.2中启动它时,我收到此错误:

android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
at android.widget.AbsListView.obtainView(AbsListView.java:1582)
at android.widget.ListView.makeAndAddView(ListView.java:1801)
at android.widget.ListView.fillDown(ListView.java:724)
at android.widget.ListView.fillFromTop(ListView.java:781)
at android.widget.ListView.layoutChildren(ListView.java:1638)
at android.widget.AbsListView.onLayout(AbsListView.java:1412)
at android.view.View.layout(View.java:7175)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:672)
at android.view.View.layout(View.java:7175)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7175)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
at android.view.View.layout(View.java:7175)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7175)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7175)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1146)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1866)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)

编辑:这些行也在那里:

07-22 16:00:52.111: E/AndroidRuntime(470): Caused by: android.content.res.Resources$NotFoundException: File res/color/abs__primary_text_holo_light.xml from xml type drawable resource ID #0x0
07-22 16:00:52.111: E/AndroidRuntime(470):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1924)
07-22 16:00:52.111: E/AndroidRuntime(470):  at android.content.res.Resources.loadDrawable(Resources.java:1692)
07-22 16:00:52.111: E/AndroidRuntime(470):  ... 42 more

我无法弄清楚原因。 我从fragment打电话给我ShelrockFragmentMainActivity}:

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, newsMasterFragment, "MasterFragment");
        bundle.putBoolean("onFirstRow", true);
        newsMasterFragment.setArguments(bundle);

在充气视图时崩溃:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_news_master,
            container, false);

3 个答案:

答案 0 :(得分:7)

如果有人遇到同样的问题,则问题是android:background

android:background="?android:attr/activatedBackgroundIndicator"

粉碎整个应用程序。所以我在pre-Honeycomb版本中删除了它

答案 1 :(得分:0)

这是因为片段API是在Android 3.0(API级别11)中引入的。

如果要在Android 2.2(API级别8)中使用它们,则必须使用Google提供的兼容性库。怎么做,你可以在这里阅读:Fragments in Android 2.2.1, 2.3, 2.0. Is this possible?

答案 2 :(得分:0)

在drawer_list_item.xml文件中

删除android:background =“?android:attr / activatedBackgroundIndicator”line

如果你想用html颜色代码改变背景。