我試圖效仿谷歌的說明導入谷歌Play遊戲服務在: https://developers.google.com/games/services/training/signin谷歌按鈕「不能被轉換爲android.widget.Button」
<!-- sign-in button -->
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
當我導入谷歌官方的播放按鈕(作爲XML佈局如上圖所示),我得到這個錯誤在我的日誌:
java.lang.RuntimeException: Unable to start activity ComponentInfo{flash4life.gespant2015.com.flashreflex20/flash4life.gespant2015.com.flashreflex20.MainActivity}: java.lang.ClassCastException: com.google.android.gms.common.SignInButton cannot be cast to android.widget.Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3255)
這是整個錯誤日誌:
08-15 19:57:25.961 472-472/flash4life.gespant2015.com.flashreflex20 E/AndroidRuntime: FATAL EXCEPTION: main
Process: flash4life.gespant2015.com.flashreflex20, PID: 472
java.lang.RuntimeException: Unable to start activity ComponentInfo{flash4life.gespant2015.com.flashreflex20/flash4life.gespant2015.com.flashreflex20.MainActivity}: java.lang.ClassCastException: com.google.android.gms.common.SignInButton cannot be cast to android.widget.Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3255)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassCastException: com.google.android.gms.common.SignInButton cannot be cast to android.widget.Button
at flash4life.gespant2015.com.flashreflex20.MainActivity.onCreate(MainActivity.java:107)
at android.app.Activity.performCreate(Activity.java:6877)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3208)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
我分配的按鈕在我的Java:
signInButton = (Button) findViewById(R.id.sign-in-button);