Android地图API,异常 [英] android maps api, exception

查看:361
本文介绍了Android地图API,异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用谷歌地图V2 IM。

我的code为crached的方法:

 公共无效onConnected(束捆){
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
如果(mLastLocation!= NULL){
    mLatitudeText.setText(将String.valueOf(mLastLocation.getLatitude()));
        mLongitudeText.setText(将String.valueOf(mLastLocation.getLongitude()));
}
 } //结束onConnected
 

logcat的:

  10月三号至25日:30:41.120 25816-25816 /? E /dalvikvm﹕找不到类的android.app.AppOpsManager,从法com.google.android.gms.common.GooglePlayServicesUtil.zza引用
十月三号至25日:30:41.460 25816-25816 /? E /AndroidRuntime﹕致命异常:主要
显示java.lang.NullPointerException
    在com.example.robot.myapplication.MainActivity.onConnected(MainActivity.java:66)
 

我是怎么想的,除了在这一行:

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

但我已经创建该对象(mGoogleApiClient):

  mGoogleApiClient =新GoogleApiClient.Builder(本)
        .addConnectionCallbacks(本)
        .addOnConnectionFailedListener(本)
        .addApi(LocationServices.API)
        。建立();
 

什么我错了?

满code:

 公共类MainActivity扩展活动器具
GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener {
    私人GoogleApiClient mGoogleApiClient;

私人的位置mLastLocation;
TextView的mLatitudeText;
TextView的mLongitudeText;
私人最终静态INT CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;
私有静态最终诠释REQUEST_RESOLVE_ERROR = 1001;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
TextView的mLatitudeText =(TextView中)findViewById(R.id.mLatitudeText);
TextView的mLongitudeText =(TextView中)findViewById(R.id.mLongitudeText);
mGoogleApiClient =新GoogleApiClient.Builder(本)
        .addConnectionCallbacks(本)
        .addOnConnectionFailedListener(本)
        .addApi(LocationServices.API)
        。建立();
}
@覆盖
保护无效onResume(){
super.onResume();
mGoogleApiClient.connect();
}
@覆盖
保护无效的onPause(){
super.onPause();
 mGoogleApiClient.disconnect();
}
@覆盖
公共无效onConnected(束捆){
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
如果(mLastLocation!= NULL){
    mLatitudeText.setText(将String.valueOf(mLastLocation.getLatitude()));
        mLongitudeText.setText(将String.valueOf(mLastLocation.getLongitude()));
}
 } //结束onConnected
@覆盖
公共无效onConnectionSuspended(int i)以{
}
@覆盖
公共无效onConnectionFailed(ConnectionResult结果){
如果(result.hasResolution()){
    尝试 {
        result.startResolutionForResult(这一点,REQUEST_RESOLVE_ERROR);
    }
    赶上(IntentSender.SendIntentException E){
        e.printStackTrace();
    }
如果} //结束

} //结束onConnectionFailed
}
 

解决方案

相关联的这个错误signuping。

更改API的版本并重新检查谷歌播放服务。

<一个href="http://stackoverflow.com/questions/20148526/google-game-services-sign-in-issue-fails-first-attempt-successful-second">Google在发行游戏服务号(失败的第一次尝试,成功的第二个)

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

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
}

解决方案

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

这篇关于Android地图API,异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆