如何解决android.view.InflateException?在Lollipop上工作正常但在其他版本上没有

时间:2015-09-28 20:59:21

标签: android android-compatibility

我制作了我的第一个应用程序,在此过程中,我仅在棒棒糖API23设备上测试了应用程序。 现在我正在尝试在软糖上运行相同的应用程序,但它在那里崩溃

09-28 16:46:44.507    9517-9517/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
        at android.view.LayoutInflater.createView(LayoutInflater.java:620)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
        at com.zap.Kalanjali.FirstHome$MyAdapter.getView(FirstHome.java:88)
        at android.widget.AbsListView.obtainView(AbsListView.java:2177)
        at android.widget.ListView.makeAndAddView(ListView.java:1840)
        at android.widget.ListView.fillDown(ListView.java:675)
        at android.widget.ListView.fillFromTop(ListView.java:736)
        at android.widget.ListView.layoutChildren(ListView.java:1655)
        at android.widget.AbsListView.onLayout(AbsListView.java:2012)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
        at android.widget.ScrollView.onLayout(ScrollView.java:1459)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
        at android.view.View.layout(View.java:14289)
        at android.view.ViewGroup.layout(ViewGroup.java:4562)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
        at android.view.Choreographer.doCallbacks(Choreographer.java:562)
        at android.view.Choreographer.doFrame(Choreographer.java:532)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
        at android.os.Handler.handleCallback(Handler.java:730)
        at android.os.Handler.dispatchMes

和FirstHome片段中的第88行是:

itemView = getActivity().getLayoutInflater().inflate(R.layout.card_list_item, parent, false);

我该如何解决这个问题?为了使应用程序与所有API级别兼容,我需要记住哪些事项?

0 个答案:

没有答案