gpt4 book ai didi

android - 地理编码器是否适用于模拟器

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:28 25 4
gpt4 key购买 nike

我正在使用地理编码器,它在我的设备上工作得很好,但不能在模拟器上工作,在 2.2 和 4.2.2 上试过它没有工作;

这是我的代码:

Geocoder myLocation = new Geocoder(AzanTime.this, Locale.getDefault());
List<Address> myList=null;
try {
myList = myLocation.getFromLocation(latitude,longitude, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Address address = (Address) myList.get(0);
String addressStr = "";
if(address.getAddressLine(0)!=null){
addressStr += address.getAddressLine(0);

}

和 logcat:

01-11 09:31:07.573: E/AndroidRuntime(788): FATAL EXCEPTION: main
01-11 09:31:07.573: E/AndroidRuntime(788): java.lang.RuntimeException: Unable to start activity ComponentInfo{amina.myhomebusiness.IslamicApps.FortressOfTheMuslimExplanation/amina.myhomebusiness.IslamicApps.FortressOfTheMuslimExplanation.AzanTime}: java.lang.IllegalArgumentException: provider doesn't exisit: null
01-11 09:31:07.573: E/AndroidRuntime(788): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.os.Handler.dispatchMessage(Handler.java:99)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.os.Looper.loop(Looper.java:137)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-11 09:31:07.573: E/AndroidRuntime(788): at java.lang.reflect.Method.invokeNative(Native Method)
01-11 09:31:07.573: E/AndroidRuntime(788): at java.lang.reflect.Method.invoke(Method.java:511)
01-11 09:31:07.573: E/AndroidRuntime(788): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-11 09:31:07.573: E/AndroidRuntime(788): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-11 09:31:07.573: E/AndroidRuntime(788): at dalvik.system.NativeStart.main(Native Method)
01-11 09:31:07.573: E/AndroidRuntime(788): Caused by: java.lang.IllegalArgumentException: provider doesn't exisit: null
01-11 09:31:07.573: E/AndroidRuntime(788): at android.os.Parcel.readException(Parcel.java:1429)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.os.Parcel.readException(Parcel.java:1379)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:538)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:836)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:430)

01-11 09:31:07.573: E/AndroidRuntime(788): at android.app.Activity.performCreate(Activity.java:5104)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-11 09:31:07.573: E/AndroidRuntime(788): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-11 09:31:07.573: E/AndroidRuntime(788): ... 11 more

最佳答案

模拟器上没有安装 Geocoder。根据Geocoder引用

The Geocoder class requires a backend service that is not included in the core android framework. The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists.

你应该检查过

Geocoder.isPresent()

在访问 API 之前。使用您自己的实现更可靠。检查此答案以了解我的实现情况。 problems with android.location.geocoder

关于android - 地理编码器是否适用于模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21061175/

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