【问题标题】:The import com.google.android.gms.location.LocationClient cannot be resolved after formatting computer格式化电脑后无法解析导入的com.google.android.gms.location.LocationClient
【发布时间】:2014-12-19 18:34:06
【问题描述】:

我格式化了我的电脑并再次导入了我使用 Google Maps API V2 完成的 android 项目并发现了许多错误。我重新链接了 google_play_services_lib 和 android-support-v7-appcompat。我仍然发现导入 com 时出错.google.android.gms.location.LocationClient.Only 调用“LocationClient”会出错,其他的导入正常。

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
(ERROR)import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

并在我使用 R. 调用的所有地方找到错误。 错误:R 无法解析为变量

setContentView(R.layout.activity_main); EditText et = (EditText) findViewById(R.id.editText1);

并在控制台中收到以下错误。

[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:121: error: Error: No resource found that matches the given name: attr 'android:colorControlHighlight'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:119: error: Error: No resource found that matches the given name: attr 'android:colorControlNormal'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:116: error: Error: No resource found that matches the given name: attr 'android:colorPrimary'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:117: error: Error: No resource found that matches the given name: attr 'android:colorPrimaryDark'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:155: error: Error: No resource found that matches the given name: attr 'android:colorAccent'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:157: error: Error: No resource found that matches the given name: attr 'android:colorControlActivated'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:158: error: Error: No resource found that matches the given name: attr 'android:colorControlHighlight'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:156: error: Error: No resource found that matches the given name: attr 'android:colorControlNormal'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:153: error: Error: No resource found that matches the given name: attr 'android:colorPrimary'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:154: error: Error: No resource found that matches the given name: attr 'android:colorPrimaryDark'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:192: error: Error: No resource found that matches the given name: attr 'android:colorAccent'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:194: error: Error: No resource found that matches the given name: attr 'android:colorControlActivated'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:195: error: Error: No resource found that matches the given name: attr 'android:colorControlHighlight'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:193: error: Error: No resource found that matches the given name: attr 'android:colorControlNormal'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:190: error: Error: No resource found that matches the given name: attr 'android:colorPrimary'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:191: error: Error: No resource found that matches the given name: attr 'android:colorPrimaryDark'.
[2014-12-19 23:22:44 - MapsProject] 

【问题讨论】:

  • 请参阅this question 了解如何将您的应用程序切换到 FusedLocationProviderApi。

标签: android google-play-services android-appcompat r.java-file location-client


【解决方案1】:

LocationClient 不久前被弃用,最近显然已从 Play 服务中删除。您需要切换到使用GoogleApiClient 来获取LocationServices.APIThis sample project 演示了如何执行此操作。基本上:

第 1 步:设置任何使用 API 的 GoogleApiClient 数据成员:

private GoogleApiClient client=null;

步骤#2:请求LocationServices.API

client=new GoogleApiClient.Builder(host)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

第 3 步:在您的 GoogleApiClient.ConnectionCallbacks 中的 onConnected() 中,开始使用 LocationServices.FusedLocationApi 处理位置(例如,致电 getLastLocation()

【讨论】:

  • setContentView(R.layout.activity_main); 中的错误是什么? EditText et = (EditText) findViewById(R.id.editText1); R 无法解析为变量
  • @SNT93:您似乎在使用appcompat-v7,因此您需要将构建目标(例如,项目 > 属性 > Android)设置为 API 级别 21 或更高。这与LocationClient 无关。
  • @SNT93:我建议您查看我在回答中链接到的示例项目。还有this blog post 和其他各种堆栈溢出答案like this one。不幸的是,谷歌还没有记录这些东西,所以我不能指给你看文档。
  • 如何使用 GoogleAPIClient 开始地图 以前我使用 if(initMap()) {mLocationClient = new LocationClient(this,this,this); mLocationClient.connect();} else { Toast.makeText(this,"地图不可用!",Toast.LENGTH_SHORT).show(); }
  • @SNT93:该代码不会启动地图。你可以在这里做同样的事情,只是在你的if 块中使用GoogleApiClient 的东西。
【解决方案2】:

来自https://developers.google.com/android/guides/api-client

当您想要连接到所提供的 Google API 之一时 在 Google Play 服务库(例如 Google+、游戏或 Drive),你需要创建一个 GoogleApiClient 的实例(“Google API 客户端”)。Google API 客户端为所有用户提供了一个通用入口点 Google Play 服务并管理两者之间的网络连接 用户的设备和每项 Google 服务。

【讨论】:

    【解决方案3】:

    您是否在同一文件夹中导入了 google play 库?我的意思是在导入时有一个选项将项目复制到现有工作区。导入时检查。

    【讨论】:

    • 是的,我做到了。两个参考文献都带有绿色刻度
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 2021-12-14
    • 2020-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多