错误引用一个内部类景观布局/ main.xml中 [英] Error referencing an inner class View in layout/main.xml

查看:138
本文介绍了错误引用一个内部类景观布局/ main.xml中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哎呀...

我创建的视图子类在我活动的内部类。以前我只是链接到该观点从我的活动有:

I create a subclass of view as an inner class in my Activity. Before I simply linked to this view from my activity with:

setContentView(new CustomView(this));

没有问题。

现在,但是,我的看法变得越来越复杂,所以我使之成为的FrameLayout的一部分,这样我可以使这个基本视图,并添加微调部件在它上面。问题是,当我这样做,我得到一个错误:

Now, however, my view is getting more complex so I am making it part of a FrameLayout so that I can make this the base view and add a Spinner widget on top of it. The problem is, when I do this I get an error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.grafightscratch.ochemmer/com.grafightscratch.ochemmer.MoleculeTablet}: android.view.InflateException: Binary XML file line #4: Error inflating class com.grafightscratch.ochemmer.MoleculeTablet.MoleculeTabletView
...
Caused by: android.view.InflateException: Binary XML file line #4: Error inflating class com.grafightscratch.ochemmer.MoleculeTablet.MoleculeTabletView
...
Caused by: java.lang.ClassNotFoundException: com.grafightscratch.ochemmer.MoleculeTablet.MoleculeTabletView in loader dalvik.system.PathClassLoader@43b74a28

所以 - 这个观点工作时,我直接联系过,但是当我试图在main.xml中的文件添加为的FrameLayout的一部分,我得到了上面的错误。我也尝试投入只用它的布局正在通过显示的:

So- this view worked before when I linked to it directly, but when I tried to add it in the main.xml file as part of a framelayout I got the above error. I also tried putting into a layout with only it being displayed via:

<com.grafightscratch.ochemmer.MoleculeTablet.MoleculeTabletView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/molecule_tablet_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

没有什么工作。我不断收到InflateException / ClassNotFoundException的错误。它抱怨二进制XML文件中的行#3,如果在谈论main.xml中这是我所三重检查包声明。

Nothing works. I keep getting the InflateException/ClassNotFoundException errors. It complains about "line #3" in the binary XML file, and if it is talking about main.xml that is the package declaration which I have triple checked.

修改 我试图使这一观点一个单独的类(即 - 不是一个内部类)和它的作品。经过一番摸索,我发现一些帖子说,XML标记应该是这样的:

EDIT I tried making this view a separate class (ie- not an inner class) and it works. After some searching around I found some posts saying that the xml tag should look like this:

<com.grafightscratch.ochemmer.MoleculeTablet$MoleculeTabletView ...>

也就是说,美元符号应当被用于将内部类从主类分离。然而,Eclipse的barfs这一点,称之为一个错误,并拒绝让我建立或部署与性格存在。所以,现在的问题是:如何做一个参考视图是一个内部类

Ie, a dollar sign should be used to separate the innerclass from the main class. However, Eclipse barfs on this, calls it an error, and refuses to let me build or deploy with that character there. So now the question becomes: how does one reference a View that is an inner class?

推荐答案

有关内部类的语法变为:

For inner classes the syntax becomes:

<view class="com.grafightscratch.ochemmer.MoleculeTablet$MoleculeTabletView" />

原因在于$非法字符在XML标记。

The reason is that $ is an illegal character in XML tags.

这篇关于错误引用一个内部类景观布局/ main.xml中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆