Android的 - 充气的RelativeLayout作为按钮? [英] Android - RelativeLayout inflated as Button?

查看:139
本文介绍了Android的 - 充气的RelativeLayout作为按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题。当运行我的Andr​​oid应用程序,我收到异常:

I have a weird problem. While running my Android application, I receive Exception:

java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.RelativeLayout

在code,其中我试图让RelativeLayout的

the code, where I try to get relativeLayout

v = inflater.inflate(R.layout.home, null);
RelativeLayout btn = (RelativeLayout) v.findViewById(R.id.my_button);

在XML中,我有这样的:

in xml, I've got this:

<RelativeLayout                
                android:id="@+id/my_button" 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@drawable/button_selector"/>

调试时,我注意到,在v在按钮具有中级等于R.id.my_button。

While debugging, I've noticed that in v there is Button with mID equals to R.id.my_button.

虽然,当我在XML和code到别的改变ID,我收到NullPointerException异常。

Although, when I change id in xml and code to anything else, I receive NullPointerException.

任何想法,为什么这会发生?

Any ideas why this is happen ?

编辑:
也许这将是有益的,如果我补充一点,在旧版本的文件有按钮,但RelativeLayout的被换下。我使用GIT。项目被清理了很多次,也已重新启动蚀。

Maybe it will be helpful, if I add that in older version of that file there was Button, but was replaced with RelativeLayout. I'm using GIT. Project was cleaned many times and eclipse was restarted also.

推荐答案

问题是,我做了,我忘了多一个布局文件,它是在同一活动BYT不同的配置。问题解决了。

The problem was that I've made one more layout file that I forgot about and it was for the same Activity byt different configuration. Problem solved.

这篇关于Android的 - 充气的RelativeLayout作为按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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