Sunday, 11 August 2013

java.ClassCastException in Android

java.ClassCastException in Android

I am getting a class cast exception "cannot convert List View to
Widget.Button". But I am not doing that.
Android Layout XML :
<Button
android:id="@+id/ab"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Puzzle Solver"
android:background="@drawable/red_button"
style="@style/ButtonText">
</Button>
Android Code at which the exception is thrown :
Button my_input=(Button)findViewById(R.id.ab);
There is no other element with the id ab. As you can see, ab is declared
as a button in the XML file and is cast as Button in the code also.
Why is the exception thrown and what is the solution for this?

No comments:

Post a Comment