Android Geocoder.getLocationFromName()引发IOException:设备上不提供服务

Android Geocoder.getLocationFromName()引发IOException:设备上不提供服务,android,geolocation,geocoding,Android,Geolocation,Geocoding,我在emulator和我的手机(Android 4.1的Nexus S)上都使用了Geocoder.getLocationFromName()方法,出现以下异常: java.io.IOException: Service not Available emulator()上出现了许多关于这一点的问题,大多数问题都说是emulator的特定版本出现了问题。但是,我的AVD(2.3和4.1)和手机上都会出现此异常 我的手机和AVD都有互联网连接。我的API版本是16(安卓4.1),但我也尝试了旧版本

我在emulator和我的手机(Android 4.1的Nexus S)上都使用了Geocoder.getLocationFromName()方法,出现以下异常:

java.io.IOException: Service not Available
emulator()上出现了许多关于这一点的问题,大多数问题都说是emulator的特定版本出现了问题。但是,我的AVD(2.3和4.1)和手机上都会出现此异常

我的手机和AVD都有互联网连接。我的API版本是16(安卓4.1),但我也尝试了旧版本。两个AVD都包含谷歌API

你知道这是怎么回事吗

这是相关的代码片段:

Geocoder myGeocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
List<Address> newAddresses = myGeocoder.getFromLocationName(arg0.toString(), 10);
Geocoder myGeocoder=new Geocoder(getApplicationContext(),Locale.getDefault());
List newAddresses=myGeocoder.getFromLocationName(arg0.toString(),10);
这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.asdasd" android:versionCode="6" android:versionName="1.3.1">
    <uses-sdk android:minSdkVersion="16" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <application android:icon="@drawable/ic_launcher_asdasd"
        android:label="@string/app_name">
        <activity android:name=".AsdasdActivity" android:label="@string/app_name"
            android:screenOrientation="portrait" android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation" />
    </application>
</manifest>

确保应用程序的构建目标设置为谷歌API之一,而不仅仅是Android 4.0(或类似版本)。您可以在Eclipse中更改此设置,方法是右键单击您的项目并选择“属性”,然后选择“Android”。或者,您也可以简单地将
project.Properties
文件编辑为以下内容:

# Project target
target=Google Inc.:Google APIs:16

原因是,
Geocoder
类存在于核心Android框架中,但它依赖于GoogleAPI提供的代码来正常工作。即使您的AVD包含Google API,您的项目仍然需要针对特定的构建目标进行构建。

谢谢您的回答。但正如我已经说过的,我使用的是谷歌API AVD。我的手机上也有同样的问题。嘿@MarkosFragkakis,你说你在AVD中使用Google API,但是你的项目的构建目标也设置为相同的Google API级别吗?这是两种不同的设置。你是对的。我将目标更改为您建议的目标(通过Eclipse)。然而,现在我得到了一个“java.io.IOException:无法解析来自服务器的响应”。我假设这是一个不同的问题,所以我会将您的答案标记为正确答案。不过,如果您有任何建议,我们非常欢迎。谢谢。我到处寻找答案,结果就是这么简单。谢谢Markos Fragkakis的提问,也谢谢twaddington的回答解决了我的问题。这很有效@twaddington你救了我的命。仅供参考,也可能与这个问题有关:重新启动设备似乎可以解决这个问题。无论我重新启动了多少次,在我的情况下都没有任何作用。