ImageButton


#1

Using an ImageButton crashes the program on my device.

08-10 11:09:41.437: E/AndroidRuntime(1991): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstandroidapp/com.example.myfirstandroidapp.MainActivity}: java.lang.ClassCastException: android.widget.ImageButton

<ImageButton
    android:id="@+id/previous_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:contentDescription="@string/previousArrowText"
    android:src="@drawable/arrow_left" />

<ImageButton
    android:id="@+id/next_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:contentDescription="@string/nextArrowText"
    android:src="@drawable/arrow_right" />

my device is running 2.3.5

Thanks!

Aaron


#2

Here’s the tricky thing about ImageButton: ImageButton is not a subclass of Button. If you try to cast it to Button, you’ll get a cast exception.


#3

Thanks again for the quick reply. I got it:

the line “Of course, you will need to modify QuizActivity to work with ImageButton” was a hint about the other changes you need to make.