0

im using google maps v2.

my code is crached at method:

public void onConnected(Bundle bundle) {
    mLastLocation =     LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mLastLocation != null) {
    mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
        mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
}
 } // end onConnected

logcat:

03-25 10:30:41.120  25816-25816/? E/dalvikvm﹕ Could not find class            'android.app.AppOpsManager', referenced from method             com.google.android.gms.common.GooglePlayServicesUtil.zza
03-25 10:30:41.460  25816-25816/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
    at         com.example.robot.myapplication.MainActivity.onConnected(MainActivity.java:66)

how i think, exception in this line:

mLastLocation =         LocationServices.FusedLocationApi.getLastLocation(**mGoogleApiClient**);

but i already create this object (mGoogleApiClient):

mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(LocationServices.API)
        .build();

whats wrong with me?

full code:

public class MainActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks,                     GoogleApiClient.OnConnectionFailedListener  {
    private GoogleApiClient mGoogleApiClient;

private Location mLastLocation;
TextView mLatitudeText;
TextView mLongitudeText;
private final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;
private static final int REQUEST_RESOLVE_ERROR = 1001;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView mLatitudeText = (TextView) findViewById(R.id.mLatitudeText);
TextView mLongitudeText = (TextView) findViewById(R.id.mLongitudeText);
mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(LocationServices.API)
        .build();
}
@Override
protected void onResume() {
super.onResume();
mGoogleApiClient.connect();
}
@Override
protected void onPause() {
super.onPause();
 mGoogleApiClient.disconnect();
}
@Override
public void onConnected(Bundle bundle) {
mLastLocation =         LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mLastLocation != null) {
    mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
        mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
}
 } // end onConnected
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (result.hasResolution()) {
    try {
        result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
    }
    catch (IntentSender.SendIntentException e) {
        e.printStackTrace();
    }
} //end if

} // end onConnectionFailed
}
si4re
  • 1
  • 1
  • 2
  • Move this code `mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build();` on `onCreate()` method. – Piyush Mar 26 '15 at 10:39
  • Do you have all correct permission inside your android manifest file? – Yahor10 Mar 26 '15 at 10:45
  • Which android api lvl do you use? – Yahor10 Mar 26 '15 at 10:46

1 Answers1

0

This error associated with signuping.

Change your api version and recheck google play services.

Google game services sign in issue (fails first attempt, successful second)

https://github.com/fbricker/openfl-admob/issues/2

Community
  • 1
  • 1
Yahor10
  • 2,123
  • 1
  • 13
  • 13