1

我需要初始化 AppStateClient 以使用 Cloud 来保存和加载数据。我接下来做:

public Constructor() {
(1) private GameHelper aHelper = new GameHelper(this);    
(2) aHelper.setup(this, GameHelper.CLIENT_APPSTATE | GameHelper.CLIENT_GAMES);
(3) private AppStateClient mHelper = aHelper.getAppStateClient();
}

但在第二个字符串中,我总是得到 NullPointerException。在 Goggle 的 GameHelper 类中,它崩溃:

 mGamesClient = new GamesClient.Builder(getContext(), this, this)
                    .setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
                    .setScopes(mScopes)
                    .create();
and on:  

mAppStateClient = new AppStateClient.Builder(getContext(), this, this)
                    .setScopes(mScopes)
                    .create();

我做错了什么?

我在我的应用程序中也用于成就和排行榜的 aHelper 变量,一切正常。

4

1 回答 1

0

问题已解决。

public Constructor() {
 private GameHelper aHelper = new GameHelper(this);    
 aHelper.setup(this, GameHelper.CLIENT_APPSTATE | GameHelper.CLIENT_GAMES);
 private AppStateClient mHelper = aHelper.getAppStateClient();
}

此代码需要调用 onCreate(Bundle savedInstanceState) 而不是类的构造函数

@Override
  public void onCreate(Bundle savedInstanceState) {
private GameHelper aHelper = new GameHelper(this);    
     aHelper.setup(this, GameHelper.CLIENT_APPSTATE | GameHelper.CLIENT_GAMES);
     private AppStateClient mHelper = aHelper.getAppStateClient();
}
于 2013-07-02T14:51:39.377 回答