我正在使用谷歌地图 v2。
我的代码在方法上被破解:
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)
我怎么想,这一行的例外:
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(**mGoogleApiClient**);
但我已经创建了这个对象(mGoogleApiClient):
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
我怎么了?
完整代码:
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
}
此错误与注册相关。
更改您的 api 版本并重新检查 google play 服务。
Google 游戏服务登录问题(第一次尝试失败,第二次成功) https://stackoverflow.com/questions/20148526/google-game-services-sign-in-issue-fails-first-attempt-successful-second
https://github.com/fbricker/openfl-admob/issues/2 https://github.com/fbricker/openfl-admob/issues/2
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)