-3

私はAndroidプログラミングのImageButtonに問題があります、誰かが私がそれを解決するのを手伝ってくれるなら、私はlogcatを置きます:

java.lang.RuntimeException:アクティビティを開始できませんComponentInfo {com.app/com.app.MainActivity}:java.lang.ClassCastException:android.widget.ImageButtonをandroid.widget.Buttonにキャストできません...原因:java .lang.ClassCastException:android.widget.ImageButtonをandroid.widget.Buttonにキャストできません

4

2 に答える 2

3
ImageButton b = (ImageButton) findViewById(R.id.myImageButton);

http://developer.android.com/reference/android/widget/ImageButton.html

From the log you're casting it to a Button, not an ImageButton. Two distinctly different objects.

于 2013-02-15T00:05:58.983 に答える
2

This means that you cannot cast an ImageButton to a Button. Instead you need to approach your casting situation differently.

And the reason they canotn be casted is because:

Following the flow of an ImageButton:

java.lang.Object ↳ android.view.View ↳ android.widget.ImageView ↳ android.widget.ImageButton

Conclusion

Since it does not extend Button, you therefore cannot cast it to that type. Although the name is a misnomer because its called ImageButton..

于 2013-02-15T00:06:02.757 に答える