2014-01-11 76 views
3

我使用的是地理編碼器,它在我的設備上工作得很好,但在仿真器上工作並沒有在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 
+1

不適用於某些版本。我的記憶有點朦朧,但我認爲2.1是好的 – NickT

回答

3

模擬器上沒有安裝Geocoder。 Accroding到Geocoder參考

地址解析器類需要一個未包括在覈心Android框架的後端服務。如果平臺中沒有後端服務,Geocoder查詢方法將返回一個空列表。使用isPresent()方法來確定Geocoder實現是否存在。

您應該檢查

Geocoder.isPresent() 

訪問API之前。 使用您自己的實現更可靠。 查看我的實施答案。 problems with android.location.geocoder

相關問題