gpt4 book ai didi

android - 膨胀类 android.view.ViewGroup 时出错

转载 作者:行者123 更新时间:2023-12-04 22:20:10 24 4
gpt4 key购买 nike

我正在尝试为 checkboxPreferences 编写自定义 View 。我有:

<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>

问题出在我的 View 组上。我收到一个异常(exception):

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是一个抽象类。

使用另一个布局作为 RelativeLayoutLinearLayout

在 LogCat 中,您有:

E/AndroidRuntime(12286): Caused by: java.lang.InstantiationException: can't instantiate class android.view.ViewGroup

关于android - 膨胀类 android.view.ViewGroup 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28988527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com