gpt4 book ai didi

java - GoogleApiAvailability.getErrorDialog(android.app.Activity, int, int)

转载 作者:太空宇宙 更新时间:2023-11-04 11:52:39 34 4
gpt4 key购买 nike

我遇到一个问题,当我直接在手机上运行应用程序时,应用程序启动成功,但当我在模拟器上尝试它时,它在启动之前崩溃并出现错误:

 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 登录仅在模拟器上出现问题:/有什么想法吗?

最佳答案

您需要检查 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;
}

如果不可用,则您可以显示一个对话框,表明所需的 Google Play 服务不支持该设备

关于java - GoogleApiAvailability.getErrorDialog(android.app.Activity, int, int),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41661651/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com