错误:(230, 25) 错误:无法访问 com.google.android.gms.common.internal.safeparcel.zza 的 zza 类文件未找到

2024-03-16

package com.example.qpay.currentlocation;
import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
//import com.google.android.gms.location.LocationListener;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        LocationListener
{

    private GoogleMap mMap;
    SupportMapFragment mapFrag;
    LocationRequest mLocationRequest;
    GoogleApiClient mGoogleApiClient;
    Location mLastLocation;
    Marker mCurrLocationMarker;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);

        mapFragment.getMapAsync(this);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap)
    {
        // Add a marker in Sydney and move the camera
        mMap=googleMap;
        mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

        //Initialize Google Play Services
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ContextCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_FINE_LOCATION)
                    == PackageManager.PERMISSION_GRANTED) {
                //Location Permission already granted
                buildGoogleApiClient();
                mMap.setMyLocationEnabled(true);
            } else {
                //Request Location Permission
                checkLocationPermission();
            }
        }
        else {
            buildGoogleApiClient();
            mMap.setMyLocationEnabled(true);
        }
    }

    public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99;
    private void checkLocationPermission() {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED) {

            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.ACCESS_FINE_LOCATION)) {

                // Show an explanation to the user *asynchronously* -- don't block
                // this thread waiting for the user's response! After the user
                // sees the explanation, try again to request the permission.
                new AlertDialog.Builder(this)
                        .setTitle("Location Permission Needed")
                        .setMessage("This app needs the Location permission, please accept to use location functionality")
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                //Prompt the user once explanation has been shown
                                ActivityCompat.requestPermissions(MapsActivity.this,
                                        new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                                        MY_PERMISSIONS_REQUEST_LOCATION );
                            }
                        })
                        .create()
                        .show();


            } else {
                // No explanation needed, we can request the permission.
                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                        MY_PERMISSIONS_REQUEST_LOCATION );
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case MY_PERMISSIONS_REQUEST_LOCATION: {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                    // permission was granted, yay! Do the
                    // location-related task you need to do.
                    if (ContextCompat.checkSelfPermission(this,
                            Manifest.permission.ACCESS_FINE_LOCATION)
                            == PackageManager.PERMISSION_GRANTED) {

                        if (mGoogleApiClient == null) {
                            buildGoogleApiClient();
                        }
                        mMap.setMyLocationEnabled(true);
                    }

                } else {

                    // permission denied, boo! Disable the
                    // functionality that depends on this permission.
                    Toast.makeText(this, "permission denied", Toast.LENGTH_LONG).show();
                }
                return;
            }

            // other 'case' lines to check for other
            // permissions this app might request
        }
    }

    protected synchronized void buildGoogleApiClient() {
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
        mGoogleApiClient.connect();
    }


    @Override
    public void onPause() {
        super.onPause();

        //stop location updates when Activity is no longer active
        if (mGoogleApiClient != null) {
            LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, (com.google.android.gms.location.LocationListener) this);
        }
    }

    @Override
    public void onLocationChanged(Location location)
    {
        mLastLocation = location;
        if (mCurrLocationMarker != null) {
            mCurrLocationMarker.remove();
        }

        //Place current location marker
        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
        MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.position(latLng);
        markerOptions.title("Current Position");
        markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
        mCurrLocationMarker = mMap.addMarker(markerOptions);

        //move map camera
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,11));

    }

    @Override
    public void onStatusChanged(String s, int i, Bundle bundle) {

    }

    @Override
    public void onProviderEnabled(String s) {

    }

    @Override
    public void onProviderDisabled(String s) {

    }

    @Override
    public void onConnected(@Nullable Bundle bundle)
    {
        mLocationRequest = new LocationRequest();
        mLocationRequest.setInterval(1000);
        mLocationRequest.setFastestInterval(1000);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION)
                == PackageManager.PERMISSION_GRANTED) {
            // LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
            LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest, (com.google.android.gms.location.LocationListener) this);

        }
    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

    }


}

对不起,先生。这是我的主要活动代码。我在应用程序中遇到异常,该异常与 com.google.android.gms.location.LocationListner 相关。错误是 无法转换为 com.google.android.gms.location.LocationListener 我搜索了此错误的解决方案,但没有人不提供帮助。


从您添加的相关依赖项来看,您犯了一些错误,

First最重要的是,如果您正在使用Gradle v3.0或以上然后使用implementation代替compile and testImplementation or androidTestImplementation代替testCompile. compile and testCompile现已弃用(Gradle v3.0 或更高版本)。

Second,是因为你没有使用相同的version or google-play-libraries,替换这个,

compile 'com.google.android.gms:play-services-location:11.0.2'

with

implementation 'com.google.android.gms:play-services-location:11.0.8'

Finally你的依赖关系看起来像,

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.google.android.gms:play-services-maps:11.8.0'
    implementation 'com.google.android.gms:play-services-location:11.8.0'
    testImplementation 'junit:junit:4.12'
    testImplementation 'com.android.support.test:runner:1.0.1'
    testImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

}

Edit --要为标记设置可绘制,

BitmapDescriptorFactory.fromResource(R.drawable.your_icon)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

错误:(230, 25) 错误:无法访问 com.google.android.gms.common.internal.safeparcel.zza 的 zza 类文件未找到 的相关文章

  • Android中如何使用洪水填充算法?

    我是Android编程新手 最近尝试编写一个简单的应用程序 仅供练习 在这个中 我想在用户点击时为图像着色 但我不知道如何开始 我读过不同的主题 其中提到使用 洪水填充 算法 我在网上找到了它 但我不知道如何将它放入我的简单应用程序中 我找
  • 使用 Google Places Autocomplete API 的 REQUEST_DENIED 响应

    我正在开发 Android 应用程序 它使用谷歌的地点自动完成 API 当尝试点击以下网址时 我得到的答复如下 预测 状态 REQUEST DENIED 我从下面的链接获得了 API 密钥Google API 控制台 http code g
  • 我可以在 firebase android 中加载另一个用户个人资料图像吗?

    如果我有其他用户的电子邮件但我以其他用户身份登录 我是否可以加载其他用户的个人资料图像 如果您使用 Firebase Storage 那么从技术上讲是的 它只是一个您可以从中检索任何文件的文件系统 如果不伪造您的应用程序 获取 api 密钥
  • 应用程序实例是否始终在任何活动之前创建?

    在 Android 中 您可以通过扩展 Application 类并在 Manifest 中声明名称来提供您自己的 Application 类实现 我的问题是 这个实现是否总是在初始活动之前创建 或者活动可以在应用程序实例有时间创建之前启动
  • 为什么我将可绘制文件重命名为 .9.png 后出现“Some file crunching failed”?

    我正在测试 9 patch 图像 在一切正常之前 我重命名drawable file ic button beat box default png to ic button beat box default 9 png 然后我收到错误 某些
  • 如何重新定位或移动 Google Maps SDK 上的当前位置按钮?

    如何将 Objective C 中的当前位置按钮移至我的偏好 现在 我已启用它 但底角有东西挡住了它 Thanks 您可以使用 padding 将按钮向上移动 self mapView padding UIEdgeInsets top 0
  • Android Studio:lambda 不起作用[重复]

    这个问题在这里已经有答案了 当尝试使用 lambda 表达式时 我遇到了一些 Gradle 构建错误 错误 41 100 错误 source 1 7 不支持 lambda 表达式 使用 source 8 或更高版本来启用 lambda 表达
  • 如何将 EditText 传递给另一个活动?

    Intent intent new Intent this Name class intent putExtra key et getText toString startActivity intent Intent intent getI
  • 在 WebView 中完成 AdBlock

    我即将在我的 Android 应用程序中推出 WebView AdBlocking 我想知道这是否会有效地阻止广告 或者在 Webview 本身内是否还有更多工作要做 我尚未修改 基本上我有一个存储在 Android 资产中的主机文件 其中
  • Android中不同线程的数据库访问

    我有一个在 AsyncTasks 中从互联网下载数据的服务 它解析数据并将其存储在数据库中 该服务持续运行 当服务写入数据库时 活动会尝试从数据库中读取更改 我有一个数据库助手 有多种写入和读取方法 这会导致问题吗 可能尝试从两个不同的线程
  • SQLite支持android的数据类型有哪些

    谁能告诉我 SQLITE 中支持 ANDROID 的数据类型列表 我想确认 TIME 和 DATE 数据类型 这里有一个list http www sqlite org datatype3 htmlSQLite 的数据类型 支持时间和日期间
  • android 确定设备是否采用从右到左的语言/布局

    有没有办法确定设备是否使用从右到左的语言 例如阿拉伯语 而不是从左到右的语言 英语 与较旧的 API 级别 低至 10 兼容的东西是必要的 SOLUTION 我最终在接受的答案中使用了 xml 方法 接下来 我还添加了此处指示的代码 以应对
  • AnalyticsService 未在应用程序清单中注册 - 错误

    我正在尝试使用 sdk 中提供的以下文档向 Android 应用程序实施谷歌分析服务 https developers google com analytics devguides collection android v4 https d
  • 使用嵌套的 hashmap 参数发送 volley 请求

    我正在使用 android volley 框架向我的服务器发送 jsonobject 请求 get 请求工作正常 现在我想发送一个带有请求参数的 post 请求 该请求参数是嵌套的 hashmap 我重写 getparams 方法 但它期望
  • Android:确定 2.2 及更高版本上的摄像头数量

    我的应用程序需要在 Android 2 2 及更高版本上运行 我需要一种方法来确定可用摄像机的数量 有很多帖子解决了这个问题 但我找不到一个有效的 一种解决方案是简单地检测操作系统版本 任何 2 2 版本的设备都仅限于 1 个摄像头 即使该
  • 更改Android菜单的背景颜色[重复]

    这个问题在这里已经有答案了 我正在尝试将标准浅灰色更改为浅绿色 似乎没有一个简单的方法可以做到这一点 例如 通过 Android 主题 但我找到了一个解决方法 如本页所述 http tinyurl com 342dgn3 http tiny
  • Android 中的 Google Places API - 适用于个人用户的 API_KEY

    我已经浏览了与在 Android 应用程序中使用 Places API 相关的 Android 文档和其他博客 到处都建议使用 API KEY 来调用 REST 服务 API KEY 在整个项目 应用程序中都是相同的 每天的请求数限制为 1
  • 具有矢量可绘制的 ImageView 的 Resources$NotFoundException

    我遇到了崩溃 Resources NotFoundException用于在活动创建时绘制的矢量 21 日前崩溃 安卓工作室2 1 支持库24 0 0 Gradle插件2 1 0 目标SDK 23 最小SDK 15 buildTools版本
  • Android ADT Eclipse 插件,parseSDKContent 失败

    我刚刚设置了我的第一个 Android 开发环境 其中包括 日食3 5 Mac OS X 10 5 适用于 x86 mac 的 Android SDK ADT Eclipse 插件 0 9 6 我已将 set PATH 设置为我的 SDK
  • putFragment() - 片段 x 当前不在 FragmentManager 中

    上面的标题被问了很多次 但答案似乎与FragmentStatePagerAdapter这与我的问题无关 我正在使用该方法putFragment Bundle String Fragment 直接地 The 安卓文档 http develop

随机推荐

  • 在没有 numpy polyfit 的情况下在 python 中拟合二次函数

    我正在尝试将二次函数拟合到某些数据 并且我尝试在不使用 numpy 的 polyfit 函数的情况下执行此操作 从数学上讲我试图关注这个网站https neutrium net mathematics least squares fitti
  • 谷歌地图无法在科尔多瓦加载

    目前我正在尝试构建一个应该使用谷歌地图的 Cordova 应用程序 以便我可以显示路线和内容 出于测试原因 我还在服务器上放置了代码 一切都运行良好 地图可能正在加载 但是当我将项目转换为 Cordova 应用程序时 谷歌地图无法加载 我不
  • PHP 中的 ZLIB 支持是否默认启用?

    在 phpmanual 的文档中它说 PHP 中的 Zlib 支持默认未启用 您将需要 配置 PHP with zlib DIR Windows 版本的 PHP 内置了对此扩展的支持 您无需加载任何额外的扩展即可使用 这些功能 正如它所说
  • HTTP POST => 302 重定向到 GET 的正确预期行为是什么?

    POST gt 302 重定向到 GET 的正确行为是什么 在 Chrome 也可能是大多数浏览器 中 在我 POST 到希望我重定向的资源 并收到 302 重定向后 浏览器会自动在 302 位置发出 GET 这甚至是一个众所周知的模式 h
  • AuthError - 错误:Amplify 尚未正确配置

    首先 我已经使用成功完成了我的反应应用程序的配置amplify configure 我在以下人员的帮助下做到了AWS 放大文档 https docs amplify aws cli start install 然后我已成功将身份验证添加到我
  • 在 Xcode 4 中,如何将远程 GitHub 存储库添加到现有的本地项目?

    Xcode 4 中的 Git 集成非常受欢迎 但在处理远程存储库时它似乎有点不稳定 为了清楚起见 我使用 OS X 版本 10 6 7 和 Xcode 4 0 2 4A2002a 如果我创建一个新的 Xcode 4 项目并接受创建本地 Gi
  • 使用await时SynchronizationContext不流动

    我们计划在 MVVM 视图模型中使用 async await 但在单元测试此代码时遇到了难题 当使用 NUnit 和手写模拟来传递消息时 我们正在丢失当前的SynchronizationContext 最好用以下小型复制示例代码来展示 Te
  • 从 Android 7.1 应用程序快捷方式启动 Fragment(而不是 Activity)

    我决定考虑将静态快捷方式添加到应用程序中 使用此页面作为参考 https developer android com preview shortcuts html https developer android com preview sh
  • postgres crosstab,错误:提供的 SQL 必须返回 3 列

    您好 我创建了一个视图 但想要旋转它 旋转前的输出 tag1 qmonth1 qmonth2 sum1 name1 18 05 MAY 166 name2 18 05 MAY 86 name3 18 05 MAY 35 name1 18 0
  • 在 LiveCode 中的 iPhone 和 Android 设备中滚动

    我正在开发适用于 Android iPhone Windows 的 livecode 应用程序 我想将滚动条添加到组中 所以我将组的垂直滚动条设置为true对于 Windows 它与右侧的垂直滚动条配合得很好 但是当在 Android 上测
  • 为什么 C# 小数不能在没有 M 后缀的情况下初始化?

    The code public class MyClass public const Decimal CONSTANT 0 50 ERROR CS0664 产生此错误 错误CS0664 无法隐式转换为 double 类型的文字 输入 十进制
  • 使用四元数的最近邻

    给定一个四元数值 我想在一组四元数中找到它的最近邻居 为此 我显然需要一种方法来比较两个四元数之间的 距离 这种比较需要什么距离表示以及如何计算 Thanks Josh 这是一个老问题 但似乎需要更多答案 如果四元数是用于表示旋转的单位长度
  • 如何找出网页浏览者每英寸的像素数?

    谁能想到一种方法来发现用户的每英寸像素数 我想确保图像显示在网络浏览器中exactly我需要它的大小 因此使用分辨率 我可以从用户代理获得 和每英寸像素的组合我可以做到这一点 但是 我不确定是否有任何方法可以发现用户的每英寸像素数 最好使用
  • jQuery UI Multiple Droppable - 拖动整个 div 元素并克隆

    我刚刚开始使用 jQuery UI 将 div 拖到表中的列中 我有几个不同的可拖动 div 其中有不同的背景颜色和文本 并且我需要它们能够作为克隆拖动到放置区域 通过使用 jQuery UI 的示例购物车代码 效果很好 但我对其进行了编辑
  • 延迟加载+同位素

    我花了相当多的时间试图让同位素和延迟加载一起工作 问题 如果用户向下滚动 则延迟加载有效 但是如果用户使用过滤器 项目会显示在顶部 但图像不会加载 这是有人遇到同样的问题 但似乎他已经解决了 我尝试了几件事但仍然无法让它工作 这是讨论htt
  • 通过按 JButton 运行外部 jar 文件

    我正在尝试运行一个 jar 文件 该文件位于与按下 JButton 不同的目录中 我有按钮和 GUI 设置 但我不知道如何启动单独的 jar 文件 我在这段代码块中放置了什么 private void jButton1MouseReleas
  • Gradle 构建错误:SAXParseException

    在构建应用程序时 我收到以下错误 Error org xml sax SAXParseException lineNumber 0 columnNumber 0 cvc pattern valid Value build tools 23
  • 加载多个 YAML 文件(使用@ConfigurationProperties?)

    使用 Spring Boot 1 3 0 RELEASE 我有几个 yaml 文件 它们描述了程序的多个实例 我现在想将所有这些文件解析为List
  • d3.js 强制取消拖动事件

    我有一个简单的拖动事件 如果满足特定条件 我想强制取消当前正在进行的拖动 基本上就像您正在执行鼠标向上操作一样 像这样 var drag behavior d3 behavior drag on drag function if mycon
  • 错误:(230, 25) 错误:无法访问 com.google.android.gms.common.internal.safeparcel.zza 的 zza 类文件未找到

    package com example qpay currentlocation import android Manifest import android app AlertDialog import android content D