创建GamesClient对象

时间:2013-05-16 15:24:26

标签: android google-play-services

我想把我的游戏与Google Play游戏连接起来。 我的代码:

GamesClient mGamesClient; 
//...
mGamesClient = new GamesClient(null, null, null, null, null, null, 0, null);
            Log.i("MyLog", "connecting");
            try{
                mGamesClient.connect();
                Log.i("MyLog", Boolean.toString(mGamesClient.isConnected()));
                Log.i("MyLog", mGamesClient.getCurrentAccountName());
            }
            catch (Exception e){
                Log.i("MyLog", e.toString());
            }

但它不起作用。

  

FATAL EXCEPTION:主java.lang.NoClassDefFoundError:   com.google.android.gms.games.GamesClient at   com.mharezlakmh.myappp.MainActivity.onStart(MainActivity.java:85)at   android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)     在android.app.Activity.performStart(Activity.java:5018)at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)     在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2215)     在android.app.ActivityThread.access $ 600(ActivityThread.java:144)     在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1210)     在android.os.Handler.dispatchMessage(Handler.java:99)at   android.os.Looper.loop(Looper.java:137)at   android.app.ActivityThread.main(ActivityThread.java:4936)at   java.lang.reflect.Method.invokeNative(Native Method)at   java.lang.reflect.Method.invoke(Method.java:511)at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:791)     在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)at   dalvik.system.NativeStart.main(原生方法)

有什么问题?

我想我应该使用constuructor:

mGamesClient = new GamesClient(...);

但是使用文档创建的构造函数不起作用。

1 个答案:

答案 0 :(得分:1)

您不应直接构造GamesClient对象。相反,使用GamesClient.Builder构建它。

GamesClient client = GamesClient.Builder(this, this, this).create();