【问题标题】:import com.google.android.gms.location.LocationClient cannot be resolved [duplicate]无法解析导入 com.google.android.gms.location.LocationClient [重复]
【发布时间】:2015-01-19 04:23:23
【问题描述】:

我收到此编译错误。我已在同一工作区中添加了 google play services lib。然后成功添加了最新的 sdk(tools,extras)。

但不知道为什么还会出现这个错误。

import com.google.android.gms.location.LocationClient;  -->import cannot be resolved


public class Main extends Activity implements
        GooglePlayServicesClient.ConnectionCallbacks,
        GooglePlayServicesClient.OnConnectionFailedListener {

private LocationClient mLocationClient;   --->LocationClient cannot be resolved to a type


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    mLocationClient = new LocationClient(this, this, this);

}
}

控制台中:

我收到了,没有找到与给定名称匹配的资源(在“值”处,值为“@integer/google_play_services_version”)。

清单:

 <uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="21" />

   <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

........
</application>

编辑:

任何人都可以帮助我。谢谢。

【问题讨论】:

  • 检查库参考。我认为 Google Play 库参考不正确!
  • @BhavinChauhan 完全正确。我很确定。我把它放在同一个工作区
  • 根据编辑问题参考很好:) 尝试重新启动 eclipse
  • @BhavinChauhan 我尝试清理并重新启动 eclipse。但它没有用。

标签: android google-maps


【解决方案1】:

更新:docs 似乎现在更新了。

大约一周前我遇到了同样的问题,问题是因为 GooglePlayServices 库已更新,而且 LocationClient 也是 deprecated (but the docs were not updated)。您必须更新了 GooglePlayServices 库,然后才出现此错误。

因此,您需要使用 com.google.android.gms.common.api.GoogleApiClientcom.google.android.gms.location.LocationRequest,而不是使用旧的 LocationClient

请参阅 GoogleApiClientLocationRequest 的文档

【讨论】:

  • 我补充说两次导入。但仍然发生错误。
  • 请参阅 stackoverflow.com/questions/24611977/… 以解决此问题,并确保您已更新 Google Play 服务库Google 存储库。并且不要忘记在您的项目中导入更新的库。
  • 注意:此时确实所有文档都更新了:)
  • 谢谢。您的回答解决了我的问题。
【解决方案2】:

这是因为 LocationClient 已被新的 Google Play Services 弃用。而且我认为您已经使用了最新的 google play 服务。因此,您只需将 LocationClient 更改为 GoogleApiClient,将其替换为 LocationClient 以获得最新的 Google play services,这将解决您的问题。

更多内容您可以访问此Link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 2011-05-06
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 2016-03-18
    • 2019-11-25
    相关资源
    最近更新 更多