带ImageButtons的声卡

时间:2014-01-23 16:05:48

标签: android

我正在尝试制作一个声卡,但我收到了这个错误。

我可能正在阅读日志错误,但图像按钮似乎出现问题。

任何想法?

  01-23 15:59:03.667: E/AndroidRuntime(19712): FATAL EXCEPTION: main
    01-23 15:59:03.667: E/AndroidRuntime(19712): java.lang.RuntimeException: 
Unable to start activity ComponentInfo{com.example.bluffball/com.example.bluffball.Content}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at android.app.ActivityThread.access$600(ActivityThread.java:138)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at android.os.Handler.dispatchMessage(Handler.java:99)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at android.os.Looper.loop(Looper.java:213)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at android.app.ActivityThread.main(ActivityThread.java:4787)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at java.lang.reflect.Method.invokeNative(Native Method)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at java.lang.reflect.Method.invoke(Method.java:511)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at dalvik.system.NativeStart.main(Native Method)
    01-23 15:59:03.667: E/AndroidRuntime(19712): Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at com.example.bluffball.Content.onCreate(Content.java:106)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at android.app.Activity.performCreate(Activity.java:5008)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
    01-23 15:59:03.667: E/AndroidRuntime(19712):    ... 11 more
    01-23 15:59:05.789: I/Process(19712): Sending signal. PID: 19712 SIG: 9

1 个答案:

答案 0 :(得分:4)

它非常清楚地告诉你,你在第106行的'Content.java'中android.widget.ImageButton cannot be cast to android.widget.Button

你可能在那里有一个类似

的声明
Button someButton = (Button) findViewById( R.id. ... )

什么时候应该

ImageButton someButton = (ImageButton) findViewById( R.id. ... )