java – Android布局预览器在添加自定义LinearLayout时会抛出错误

java – Android布局预览器在添加自定义LinearLayout时会抛出错误,第1张

概述我定义了一个自定义ViewGroup,它扩展了LinearLayout的功能: public class TestLayout extends LinearLayout { public TestLayout(Context context, AttributeSet attrs) { super(context, attrs); LayoutInfla 我定义了一个自定义viewGroup,它扩展了linearLayout的功能:
public class TestLayout extends linearLayout {    public TestLayout(Context context,AttributeSet attrs) {        super(context,attrs);        LayoutInflater inflater = (LayoutInflater)context.getSystemService                  (Context.LAYOUT_INFLATER_SERVICE);        inflater.inflate(R.layout.testlayout,this,true);    }}

它膨胀的布局(testlayout.xml)如下所示:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:orIEntation="vertical" androID:gravity="center">    <button        androID:ID="@+ID/button1"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="button"/></linearLayout>

最后我在main.xml中使用这个自定义组件:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:orIEntation="vertical" >    <my.test.namespace.TestLayout        androID:ID="@+ID/testLayout1"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content" >    </my.test.namespace.TestLayout></linearLayout>

在布局编辑器中查看我的main.xml时,eclipse会抛出一个错误:
my.test.namespace.TestLayout无法实例化.

和堆栈跟踪:

androID.content.res.Resources$NotFoundException: Could not resolve resource value: 0x7F030001.    at com.androID.layoutlib.brIDge.androID.BrIDgeResources.throwException(BrIDgeResources.java:648)    at com.androID.layoutlib.brIDge.androID.BrIDgeResources.getLayout(BrIDgeResources.java:270)    at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:318)    at my.test.namespace.TestLayout.<init>(TestLayout.java:18)    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    at sun.reflect.NativeConstructorAccessorImpl.newInstance(UnkNown Source)    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnkNown Source)    at java.lang.reflect.Constructor.newInstance(UnkNown Source)    at com.androID.IDe.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:397)    at com.androID.IDe.eclipse.adt.internal.editors.layout.ProjectCallback.loadVIEw(ProjectCallback.java:165)    at com.androID.layoutlib.brIDge.androID.BrIDgeInflater.loadCustomVIEw(BrIDgeInflater.java:205)    at com.androID.layoutlib.brIDge.androID.BrIDgeInflater.createVIEwFromTag(BrIDgeInflater.java:133)    at androID.vIEw.LayoutInflater.rInflate(LayoutInflater.java:618)    at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:407)

0x7F030001指向R.java中的布局xml文件.我试着清理我的项目,但没有做任何事情.我使用LayoutInflater错了,还是这里发生了什么?

解决方法 以下通常有帮助:

>清理你的项目(再次,以防万一).>重启日食>在eclipse中刷新您的文件夹(右键单击 – >刷新或选择您的顶级文件夹,然后按f5).

总结

以上是内存溢出为你收集整理的java – Android布局预览器添加自定义LinearLayout时会抛出错误全部内容,希望文章能够帮你解决java – Android布局预览器在添加自定义LinearLayout时会抛出错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1148691.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存