java.lang.NoSuchMethodError:没有虚拟方法getMccString()Ljava/lang/String; [英] java.lang.NoSuchMethodError: No virtual method getMccString()Ljava/lang/String;

查看:920
本文介绍了java.lang.NoSuchMethodError:没有虚拟方法getMccString()Ljava/lang/String;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从TelephonyManager

对于每个单元格信息对象,我通过以下方式查询 mcc (移动国家/地区代码)和 mnc (移动网络代码)

For each cell info object, I am querying for mcc (Mobile Country Code) and mnc (Mobile Network Code) via

eachCellInfo.cellIdentity.mcc
eachCellInfo.cellIdentity.mnc

其中每个CellInfo是 CellInfo

Where eachCellInfo is an object of CellInfo

该功能已根据文档弃用:

The function is deprecated as per the doc:

    /**
     * @return 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
     * @deprecated Use {@link #getMncString} instead.
     */
    @Deprecated
    public int getMnc() {
        return (mMncStr != null) ? Integer.valueOf(mMncStr) : Integer.MAX_VALUE;
    }

但是,当我使用建议的方法时,

However when I am using the suggested method that is via

    eachCellInfo.cellIdentity.mccString

方法说明:

        /**
         * @return Mobile Country Code in string format, null if unknown
         */
        public String getMccString() {
            return mMccStr;
        }

我正在获取以下崩溃日志:

I am getting following crash logs:

java.lang.NoSuchMethodError: No virtual method getMccString()Ljava/lang/String; in class Landroid/telephony/CellIdentityLte; or its super classes (declaration of 'android.telephony.CellIdentityLte' appears in /system/framework/framework.jar!classes2.dex)
 )

让我知道我是否缺少任何信息以及此行为的可能原因.

Let me know if I am missing any information and possible cause of this behavior.

其他信息:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip 
kotlin_version = '1.3.21' 
classpath 'com.google.gms:google-services:4.2.0' 
classpath 'com.android.tools.build:gradle:3.3.1'
Debug Version
minifyEnabled false
shrinkResources false

推荐答案

此方法是Android api 28中引入的-检查

This method was introduced in Android api 28 - check here - which means it won't be available in versions before.

这将在运行api 28+的设备上运行,并将在运行较低api级别的设备上抛出该异常.

This will work on devices running api 28+ and will throw that exception in devices running lower api levels.

通常,正确的方法是对版本进行检查:

Usually the correct way to do this is to introduce checks for the version:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
   // Safe to use getMccString
} else {
   // Use something else that could work if there's something
}

请注意,仅仅因为您可以浏览计算机中的源代码,并不意味着运行您的应用程序的设备将在同一时间运行相同的Android代码-大多数情况下并非如此.

Note that just because you can browse the source in your machine it doesn't mean the device running your app will have the same Android code running - most of the time it doesn't.

这篇关于java.lang.NoSuchMethodError:没有虚拟方法getMccString()Ljava/lang/String;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆