我遇到了一个问题,当我直接在我的手机上运行时,应用程序启动成功,但是当我在模拟器上尝试它时,它会在错误启动之前崩溃:
01-15 14:30:35.037 3735-3735/com.example.glen.countryinformationapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.glen.countryinformationapp, PID: 3735
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Dialog com.google.android.gms.common.GoogleApiAvailability.getErrorDialog(android.app.Activity, int, int)' on a null object reference
at com.example.glen.countryinformationapp.MainActivity.onConnectionFailed(MainActivity.java:216)
at com.google.android.gms.common.internal.zzm.zzo(Unknown Source)
at com.google.android.gms.internal.zzaal.zzc(Unknown Source)
at com.google.android.gms.internal.zzaaj.zzf(Unknown Source)
at com.google.android.gms.internal.zzaaj.zza(Unknown Source)
at com.google.android.gms.internal.zzaaj$zzb$1.zzvA(Unknown Source)
at com.google.android.gms.internal.zzaan$zza.zzc(Unknown Source)
at com.google.android.gms.internal.zzaan$zzb.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我正在使用 Google Plus API 登录,这只会在模拟器上出现问题:/任何想法?
答案 0 :(得分:0)
您需要检查您的模拟器中是否提供了Google服务API ..
public boolean isGooglePlayServicesAvailable(Activity activity) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int status = googleApiAvailability.isGooglePlayServicesAvailable(activity);
if(status != ConnectionResult.SUCCESS) {
if(googleApiAvailability.isUserResolvableError(status)) {
googleApiAvailability.getErrorDialog(activity, status, 1000).show();
}
return false;
}
return true;
}
如果没有,那么您可以显示dialog
the device is not supported for required Google Play Services