3

项目只有这个代码,我只是按照这个描述。访问https://developers.google.com/games/services/android/init

制作项目并添加库“google-play-services_lib”和“BaseGameUtiles”

将 'extends Activity' 更改为 'BaseGameActivity' 并添加一些代码。

我构建并运行......我的应用程序崩溃了Java.lang.illegal

我怎样才能解决这个问题?

public class MainActivity extends BaseGameActivity implements View.OnClickListener{

    Button btnLogin;
    ImageView profilePic;
    TextView profileName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            btnLogin = (Button)findViewById(R.id.btn_login);
            profilePic = (ImageView)findViewById(R.id.img_userprofile);
            profileName = (TextView)findViewById(R.id.txt_user_name);

            btnLogin.setOnClickListener(this);
    }


    @Override
    public void onSignInFailed() {
            profileName.setText("LOGIN FAILED");
    }

    @Override
    public void onSignInSucceeded() {
            profileName.setText("LOGIN SUCCESS");
    }

    @Override
    public void onClick(View v) {
            switch(v.getId())
            {
            case R.id.btn_login:
                    beginUserInitiatedSignIn();
                    break;
            }
    }

}

错误日志:

09-15 11:06:09.420: I/dalvikvm(1753): Could not find method android.view.View.getDisplay, referenced from method com.google.android.gms.internal.bv$b.b
09-15 11:06:09.420: W/dalvikvm(1753): VFY: unable to resolve virtual method 3183: Landroid/view/View;.getDisplay ()Landroid/view/Display;
09-15 11:06:09.420: D/dalvikvm(1753): VFY: replacing opcode 0x6e at 0x0009
09-15 11:06:09.505: W/PopupManager(1753): You have not specified a View to use as content view for popups. Falling back to the Activity content view which may not work properly in future versions of the API. Use setViewForPopups() to set your content view.
09-15 11:06:09.635: D/libEGL(1753): loaded /system/lib/egl/libEGL_mali.so
09-15 11:06:09.650: D/libEGL(1753): loaded /system/lib/egl/libGLESv1_CM_mali.so
09-15 11:06:09.655: D/libEGL(1753): loaded /system/lib/egl/libGLESv2_mali.so
09-15 11:06:09.660: D/(1753): Device driver API match
09-15 11:06:09.660: D/(1753): Device driver API version: 10
09-15 11:06:09.660: D/(1753): User space API version: 10 
09-15 11:06:09.660: D/(1753): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Fri Oct 12 13:25:41 KST 2012 
09-15 11:06:09.710: D/OpenGLRenderer(1753): Enabling debug mode 0
09-15 11:06:10.080: D/AndroidRuntime(1753): Shutting down VM
09-15 11:06:10.080: W/dalvikvm(1753): threadid=1: thread exiting with uncaught exception (group=0x418412a0)
09-15 11:06:10.095: E/AndroidRuntime(1753): FATAL EXCEPTION: main
09-15 11:06:10.095: E/AndroidRuntime(1753): java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
09-15 11:06:10.095: E/AndroidRuntime(1753):     at com.google.android.gms.internal.u$f.a(Unknown Source)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at com.google.android.gms.internal.u$f.a(Unknown Source)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at com.google.android.gms.internal.u$b.A(Unknown Source)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at com.google.android.gms.internal.u$a.handleMessage(Unknown Source)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at android.os.Looper.loop(Looper.java:137)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at android.app.ActivityThread.main(ActivityThread.java:4946)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at java.lang.reflect.Method.invokeNative(Native Method)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at java.lang.reflect.Method.invoke(Method.java:511)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
09-15 11:06:10.095: E/AndroidRuntime(1753):     at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

6

您似乎忘记在清单文件中添加 APP_ID 元数据。您需要在 Android Manifest 文件的标签内准确添加以下代码:

<meta-data android:name="com.google.android.gms.games.APP_ID"
    android:value="@string/app_id" />

请确保元标签不在标签内,而是在标签内,并使用 APP_ID,即在您的游戏机中游戏标题右侧的 12 位数字。

有关更多信息,请查看以下链接: https ://developers.google.com/games/services/android/quickstart#step_3_modify_your_code

于 2013-09-15T04:29:11.023 回答