错误:(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 类文件未找到 的相关文章

  • 如何快速自动发送FCM或APNS消息?

    我正在开发一项后端服务 通过 FCM 或 APNS 向移动应用程序发送推送通知 我想创建一个可以在一分钟内运行的自动化测试 并验证服务器是否可以成功发送通知 请注意 我不一定需要检查通知是否已送达 只需检查 FCM 或 APNS 是否已成功
  • 类型容器“Android 依赖项”引用不存在的库 android-support-v7-appcompat/bin/android-support-v7-appcompat.jar

    我在尝试在我的项目中使用 Action Bar Compat 支持库时遇到了某种错误 我不知道出了什么问题 因为我已按照此链接中的说明进行操作 gt http developer android com tools support libr
  • 如何重试已消耗的 Observable?

    我正在尝试重新执行失败的已定义可观察对象 一起使用 Retrofit2 和 RxJava2 我想在单击按钮时重试特定请求及其订阅和行为 那可能吗 service excecuteLoginService url tokenModel Ret
  • Android 后退按钮无法与 Flutter 选项卡内的导航器配合使用

    我需要在每个选项卡内有一个导航器 因此当我推送新的小部件时 选项卡栏会保留在屏幕上 代码运行得很好 但是 android 后退按钮正在关闭应用程序而不是运行 Navigator pop import package flutter mate
  • 谷歌坐标认证

    当我尝试连接到 Google 坐标时 总是出现异常GoogleAuthException 我拥有 Google 地图协调中心许可证 我确实使用我的包应用程序名称和 SHA1 在 google 控制台中创建了我的客户端 ID 我将权限添加到清
  • 是否可以将数组或对象添加到 Android 上的 SharedPreferences

    我有一个ArrayList具有名称和图标指针的对象 我想将其保存在SharedPreferences 我能怎么做 注意 我不想使用数据库 无论 API 级别如何 请检查SharedPreferences 中的字符串数组和对象数组 http
  • Adobe 是否为其 PDF 阅读器提供 Android SDK 或 API? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我希望能够在我们的应用程序内的视图中显示本地 PDF 文件 在 Android 4 03 下的平板电脑上运行 目前 我们将 Adob eR
  • Android:捕获的图像未显示在图库中(媒体扫描仪意图不起作用)

    我遇到以下问题 我正在开发一个应用程序 用户可以在其中拍照 附加到帖子中 并将图片保存到外部存储中 我希望这张照片也显示在图片库中 并且我正在使用媒体扫描仪意图 但它似乎不起作用 我在编写代码时遵循官方的Android开发人员指南 所以我不
  • 尝试将相机切换回前面但出现异常

    尝试将相机切换回前面 但出现异常 找不到 问题请检查并帮助 error 01 27 11 49 00 376 E AndroidRuntime 30767 java lang RuntimeException Unable to start
  • 发布android后更改应用内购买项目的价格

    在 Google Play 上发布后 是否可以更改应用内购买商品的价格 我假设该应用程序也已发布 完整的在线文档位于http developer android com http developer android com也http sup
  • 原色(有时)变得透明

    我正在使用最新的 SDK 版本 API 21 和支持库 21 0 2 进行开发 并且在尝试实施新的材料设计指南时遇到了麻烦 材料设计说我需要有我的primary color and my accent color并将它们应用到我的应用程序上
  • 在两个活动之间传输数据[重复]

    这个问题在这里已经有答案了 我正在尝试在两个不同的活动之间发送和接收数据 我在这个网站上看到了一些其他问题 但没有任何问题涉及保留头等舱的状态 例如 如果我想从 A 类发送一个整数 X 到 B 类 然后对整数 X 进行一些操作 然后将其发送
  • 在 android DatePickerDialog 中将语言设置为法语

    有什么办法可以让日期显示在DatePickerDialog用法语 我已经搜索过这个但没有找到结果 这是我的代码 Calendar c Calendar getInstance picker new DatePickerDialog Paym
  • Android Studio 0.4.3 Eclipse项目没有gradle

    在此版本之前 在 Android Studio 中按原样打开 Eclipse 项目似乎很容易 无需任何转换 我更喜欢 Android Studio 环境 但我正在开发一个使用 eclipse 作为主要 IDE 的项目 我不想只为这个项目下载
  • .isProviderEnabled(LocationManager.NETWORK_PROVIDER) 在 Android 中始终为 true

    我不知道为什么 但我的变量isNetowrkEnabled总是返回 true 我的设备上是否启用互联网并不重要 这是我的GPSTracker class public class GPSTracker extends Service imp
  • 如何根据 gradle 风格设置变量

    我想传递一个变量test我为每种风格设置了不同的值作为 NDK 的定义 但出于某种原因 他总是忽略了最后味道的价值 这是 build gradle apply plugin com android library def test andr
  • 增加活动的屏幕亮度

    显然 Android 操作系统中至少有三种不同的技术可以改变屏幕亮度 其中两个在纸杯蛋糕之后不再起作用 而第三个被接受的技术显然有一个错误 我想在单视图活动开始时增加屏幕亮度 然后在活动结束时将亮度恢复为用户设置 没有按钮 没有第二个视图或
  • 如何确定对手机号码的呼叫是本地呼叫还是 STD 或 ISD

    我正在为 Android 开发某种应用程序 但不知道如何获取被叫号码是本地或 STD 的号码的数据 即手机号码检查器等应用程序从哪里获取数据 注意 我说的是手机号码 而不是固定电话 固定电话号码 你得到的数字是字符串类型 因此 您可以获取号
  • 将 Intent 包装在 LabeledIntent 中以用于显示目的

    要求 我的应用程序中有一个 共享 按钮 我需要通过 Facebook 分享 我需要选择是否安装原生 Facebook 应用程序 我们的决定是 如果未安装该应用程序 则将用户发送到 facebook com 进行分享 当前状态 我可以检测何时
  • android sdk 的位置尚未在 Windows 操作系统的首选项中设置

    在 Eclipse 上 我转到 windows gt Android SDK 和 AVD Manager 然后弹出此消息 Android sdk 的位置尚未在首选项中设置 进入首选项 在侧边栏找到 Android 然后会出现一个 SDK 位

随机推荐

  • 在没有 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