简体   繁体   中英

Android - RelativeLayout inflated as Button?

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

the code, where I try to get relativeLayout

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

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

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

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

Any ideas why this is happen ?

EDIT: 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.

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.

删除R.Java文件,重新创建运行该应用程序即可正常运行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM