質問

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.

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top