错误膨胀 class android.view.ViewGroup
Error inflating class android.view.ViewGroup
我正在尝试为 checkboxPreferences 编写自定义视图。我有:
<CheckBoxPreference
android:key="@string/pref_acceptableads"
android:summaryOff="@string/pref_acceptableads_summary_off"
android:summaryOn="@string/pref_acceptableads_summary_on"
android:title="@string/pref_acceptableads_title"
android:widgetLayout="@layout/helpfulcheckbox_layout" />
和:
<?xml version="1.0" encoding="UTF-8"?>
<ViewGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/image" />
<CheckBox
android:id="@+id/checkbox"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</ViewGroup>
我的视图组有问题。我收到异常:
03-11 13:49:11.520: E/AndroidRuntime(12286): FATAL EXCEPTION: main
03-11 13:49:11.520: E/AndroidRuntime(12286): Process:
org.adblockplus.android, PID: 12286 03-11 13:49:11.520:
E/AndroidRuntime(12286): android.view.InflateException: Binary XML
file line #2: Error inflating class android.view.ViewGroup 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.LayoutInflater.createView(LayoutInflater.java:620) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.view.LayoutInflater.inflate(LayoutInflater.java:469) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.LayoutInflater.inflate(LayoutInflater.java:397) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.LayoutInflater.inflate(LayoutInflater.java:353) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.preference.Preference.onCreateView(Preference.java:489) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.preference.Preference.getView(Preference.java:460) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:221)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.widget.AbsListView.obtainView(AbsListView.java:2255) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.widget.ListView.makeAndAddView(ListView.java:1790) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.widget.ListView.fillDown(ListView.java:691) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.widget.ListView.fillFromTop(ListView.java:752) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.widget.ListView.layoutChildren(ListView.java:1616) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.widget.AbsListView.onLayout(AbsListView.java:2087) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.View.layout(View.java:14841) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.View.layout(View.java:14841) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.widget.FrameLayout.onLayout(FrameLayout.java:388) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.View.layout(View.java:14841) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.view.View.layout(View.java:14841) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.widget.FrameLayout.onLayout(FrameLayout.java:388) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.View.layout(View.java:14841) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1983) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1740)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.view.Choreographer.doCallbacks(Choreographer.java:574) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.Choreographer.doFrame(Choreographer.java:544) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
android.os.Handler.handleCallback(Handler.java:733) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.os.Handler.dispatchMessage(Handler.java:95) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.os.Looper.loop(Looper.java:136) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
android.app.ActivityThread.main(ActivityThread.java:5139) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
java.lang.reflect.Method.invokeNative(Native Method) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
java.lang.reflect.Method.invoke(Method.java:515) 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
03-11 13:49:11.520: E/AndroidRuntime(12286): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
dalvik.system.NativeStart.main(Native Method) 03-11 13:49:11.520:
E/AndroidRuntime(12286): Caused by: java.lang.InstantiationException:
can't instantiate class android.view.ViewGroup 03-11 13:49:11.520:
E/AndroidRuntime(12286): at
java.lang.reflect.Constructor.constructNative(Native Method) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
java.lang.reflect.Constructor.newInstance(Constructor.java:423) 03-11
13:49:11.520: E/AndroidRuntime(12286): at
android.view.LayoutInflater.createView(LayoutInflater.java:594) 03-11
13:49:11.520: E/AndroidRuntime(12286): ... 51 more
你能帮我打一下这是怎么回事吗?
ViewGroup 是一个摘要 class.
使用另一个布局作为 RelativeLayout or LinearLayout
在 LogCat 你有:
E/AndroidRuntime(12286): Caused by: java.lang.InstantiationException: can't instantiate class android.view.ViewGroup
我正在尝试为 checkboxPreferences 编写自定义视图。我有:
<CheckBoxPreference
android:key="@string/pref_acceptableads"
android:summaryOff="@string/pref_acceptableads_summary_off"
android:summaryOn="@string/pref_acceptableads_summary_on"
android:title="@string/pref_acceptableads_title"
android:widgetLayout="@layout/helpfulcheckbox_layout" />
和:
<?xml version="1.0" encoding="UTF-8"?>
<ViewGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/image" />
<CheckBox
android:id="@+id/checkbox"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</ViewGroup>
我的视图组有问题。我收到异常:
03-11 13:49:11.520: E/AndroidRuntime(12286): FATAL EXCEPTION: main 03-11 13:49:11.520: E/AndroidRuntime(12286): Process: org.adblockplus.android, PID: 12286 03-11 13:49:11.520: E/AndroidRuntime(12286): android.view.InflateException: Binary XML file line #2: Error inflating class android.view.ViewGroup 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.createView(LayoutInflater.java:620) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652) 03-11 13:49:11.520: E/AndroidRuntime(12286): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.preference.Preference.onCreateView(Preference.java:489) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.preference.Preference.getView(Preference.java:460) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:221) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.AbsListView.obtainView(AbsListView.java:2255) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.ListView.makeAndAddView(ListView.java:1790) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.ListView.fillDown(ListView.java:691) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.ListView.fillFromTop(ListView.java:752) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.ListView.layoutChildren(ListView.java:1616) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.AbsListView.onLayout(AbsListView.java:2087) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.View.layout(View.java:14841) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.View.layout(View.java:14841) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.View.layout(View.java:14841) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520: E/AndroidRuntime(12286): at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.View.layout(View.java:14841) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.View.layout(View.java:14841) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1983) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1740) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.Choreographer.doCallbacks(Choreographer.java:574) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.Choreographer.doFrame(Choreographer.java:544) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.os.Handler.handleCallback(Handler.java:733) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.os.Handler.dispatchMessage(Handler.java:95) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.os.Looper.loop(Looper.java:136) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.app.ActivityThread.main(ActivityThread.java:5139) 03-11 13:49:11.520: E/AndroidRuntime(12286): at java.lang.reflect.Method.invokeNative(Native Method) 03-11 13:49:11.520: E/AndroidRuntime(12286): at java.lang.reflect.Method.invoke(Method.java:515) 03-11 13:49:11.520: E/AndroidRuntime(12286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796) 03-11 13:49:11.520: E/AndroidRuntime(12286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612) 03-11 13:49:11.520: E/AndroidRuntime(12286): at dalvik.system.NativeStart.main(Native Method) 03-11 13:49:11.520: E/AndroidRuntime(12286): Caused by: java.lang.InstantiationException: can't instantiate class android.view.ViewGroup 03-11 13:49:11.520: E/AndroidRuntime(12286): at java.lang.reflect.Constructor.constructNative(Native Method) 03-11 13:49:11.520: E/AndroidRuntime(12286): at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.createView(LayoutInflater.java:594) 03-11 13:49:11.520: E/AndroidRuntime(12286): ... 51 more
你能帮我打一下这是怎么回事吗?
ViewGroup 是一个摘要 class.
使用另一个布局作为 RelativeLayout or LinearLayout
在 LogCat 你有:
E/AndroidRuntime(12286): Caused by: java.lang.InstantiationException: can't instantiate class android.view.ViewGroup