“GoogleApiClient还没有连接。”应用程序崩溃

时间:2014-05-24 03:44:50

标签: java android

所以,我试图将google play服务与我的应用程序集成,而且我没有史诗般的失败,这是我的第一个应用程序,它主要用于学习目的。我收到的错误如下:

java.lang.IllegalStateException: GoogleApiClient is not connected yet.

05-23 21:49:19.712: E/AndroidRuntime(14149): FATAL EXCEPTION: Timer-1
05-23 21:49:19.712: E/AndroidRuntime(14149): java.lang.IllegalStateException: GoogleApiClient is not connected yet.
05-23 21:49:19.712: E/AndroidRuntime(14149):    at com.google.android.gms.internal.fq.a(Unknown Source)
05-23 21:49:19.712: E/AndroidRuntime(14149):    at com.google.android.gms.common.api.b.b(Unknown Source)
05-23 21:49:19.712: E/AndroidRuntime(14149):    at com.google.android.gms.games.internal.api.AchievementsImpl.unlock(Unknown Source)
05-23 21:49:19.712: E/AndroidRuntime(14149):    at com.fmeg.tapout.android.PlayServices.unlockAchievement(PlayServices.java:16)
05-23 21:49:19.712: E/AndroidRuntime(14149):    at com.fmeg.tapout.screens.GameOver.handleAchievements(GameOver.java:98)
05-23 21:49:19.712: E/AndroidRuntime(14149):    at com.fmeg.tapout.screens.GameOver.<init>(GameOver.java:36)
05-23 21:49:19.712: E/AndroidRuntime(14149):    at com.fmeg.tapout.screens.Tick.run(Play.java:85)
05-23 21:49:19.712: E/AndroidRuntime(14149):    at java.util.Timer$TimerImpl.run(Timer.java:284)

所以我想我会继续展示我所拥有的代码,以便你们可以指出我出错的地方。


private GoogleApiClient googleApi;

@Override
protected void onCreate (Bundle savedInstanceState) {
    ...
    googleApi = new GoogleApiClient.Builder(this, this, this)
    .addApi(Games.API)
    .addScope(Games.SCOPE_GAMES)
    .setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
    .build();

    googleApi.connect();
    ...
    initialize(new TapoutGame(impact, shareScore, googlePlay), config);

}

好吧,这是我的android项目的主要课程,我使用界面来调用我的方法,但这里是我更新所有内容的方法

package com.fmeg.tapout.android;

import com.fmeg.tapout.GoogleInterface;
import com.google.android.gms.games.Games;

public class PlayServices implements GoogleInterface {

    private AndroidLauncher application;

    public PlayServices(AndroidLauncher _application) {
        this.application = _application;
    }

    @Override
    public void unlockAchievement(String achievementID) {
        Games.Achievements.unlock(application.getGoogleAPI(), achievementID);
    }

    @Override
    public void achivementProgress(String achievementID, int progression) {
        Games.Achievements.increment(application.getGoogleAPI(), achievementID, progression);
    }

    @Override
    public void submitScoreToLeaderboard(String leaderboardID, int score) {
        Games.Leaderboards.submitScore(application.getGoogleAPI(), leaderboardID, score);
    }

    @Override
    public void displayLeaderboard(String leaderboardID, int request) {
        application.startActivityForResult(Games.Leaderboards.getLeaderboardIntent(application.getGoogleAPI(), leaderboardID), request);        
    }

}

因此,当我尝试使用以下代码从我的核心项目调用unlockAchievement(String)时调用错误


if(score > 200) 
    game.getGoogleInterface().unlockAchievement("idhiddenfrompublic");

我真的不知道我做错了什么,我打电话给连接,所以我应该好好照顾自己。

0 个答案:

没有答案