简体   繁体   English

VFY:无法解析静态方法10876:Android

[英]VFY: unable to resolve static method 10876: Android

I used SmsCbMessage.java class in a my program. 我在我的程序中使用了SmsCbMessage.java类。 It was taken from http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/telephony/SmsCbMessage.java#SmsCbMessage Following is my program. 它取自http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/telephony/SmsCbMessage.java#SmsCbMessage以下是我的程序。

package com.android.internal.telephony;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import android.telephony.SmsCbMessage;
import android.widget.Toast;

public class MainActivity extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //---get the CB message passed in---
        Bundle bundle = intent.getExtras();
        SmsCbMessage[] msgs = null;
        String str = "";
        if (bundle != null)  {
            //---retrieve the SMS message received---
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsCbMessage[pdus.length];
            for (int i=0; i<msgs.length; i++) {
                msgs[i] = SmsCbMessage.createFromPdu((byte[])pdus[i]);
                str += "CB lang " + msgs[i].getLanguageCode();
                str += " :";
                str += msgs[i].getMessageBody().toString();
                str += "\n";
            }
            //---display the new CB message---
            abortBroadcast();
            Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
        }
    }
}

This compiles without errors. 这编译没有错误。 But when running it gives following error 但运行时会出现以下错误

06-21 23:32:43.530    1951-1951/com.example.samitha.cbmessagespro I/dalvikvm﹕ Could not find method android.telephony.SmsCbMessage.createFromPdu, referenced from method com.android.internal.telephony.MainActivity.onReceive
06-21 23:32:43.530    1951-1951/com.example.samitha.cbmessagespro W/dalvikvm﹕ VFY: unable to resolve static method 10876: Landroid/telephony/SmsCbMessage;.createFromPdu ([B)Landroid/telephony/SmsCbMessage;
06-21 23:32:43.530    1951-1951/com.example.samitha.cbmessagespro W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41784c68)
06-21 23:32:45.580    1951-1951/com.example.samitha.cbmessagespro I/Process﹕ Sending signal. PID: 1951 SIG: 9

How to solve this? 怎么解决这个?

Not that I also included all the required dependent classes too when using that SmsCbMessage.java class. 并非我在使用SmsCbMessage.java类时也包含了所有必需的依赖类。

if you look at the sourcecode of SmsCbMessage@android.googlesource.com 如果你看一下SmsCbMessage@android.googlesource.com的源代码

you will see that the class is marked with the "@hide" attribute 您将看到该类标有“@hide”属性

 /*
 * ....
 * @hide
 */
public class SmsCbMessage implements Parcelable {...

This means that the class is an implementation detail of android that is not part of the public android api and that can be changed or removed without notice. 这意味着该类是android的实现细节,它不是公共android api的一部分,可以更改或删除,恕不另行通知。

SmsCbMessage@android.googlesource.com does hot have the method public static SmsCbMessage createFromPdu(byte[] pdu) while your codefragment does have it. SmsCbMessage@android.googlesource.com热门的方法是public static SmsCbMessage createFromPdu(byte[] pdu)你的codefragment确实拥有它。

Your Test-Device does have this class but without the static method. 您的测试设备确实有这个类但没有静态方法。

If you want to use the class anyway you can add the sourcecode to your project and rename the package 如果您仍想使用该类,可以将源代码添加到项目中并重命名该包

[Update 2015-06-25] [更新2015-06-25]

Since adding source from grepcodes to local project does not solve the problem because it has to many dependencies (especially android.internal.*) 因为从grepcodes添加源到本地项目不能解决问题,因为它有许多依赖项(特别是android.internal。*)

you can create your own MySmsCbMessage that inherits from devices SmsCbMessage class and try to add missing functions from grepcodes source. 您可以创建自己的MySmsCbMessage,它继承自设备SmsCbMessage类,并尝试从grepcodes源添加缺少的函数。

public class MySmsCbMessage extends SmsCbMessage {

    public static SmsCbMessage createFromPdu(byte[] pdu) {

         try {
             return new MySmsCbMessage(pdu);
         } catch (IllegalArgumentException e) {
             Log.w(LOG_TAG, "Failed parsing SMS-CB pdu", e);
             return null;
         }
     }
}

This is still a fragile workaround because you cannot be shure that other devices will have SmsCbMessage 这仍然是一个脆弱的解决方法,因为您不能避免其他设备将具有SmsCbMessage

It is probable that Huawei has customized the SmsCbMessage class. 华为很可能已经定制了SmsCbMessage类。 What you can do is to use reflection to see what methods are available on that class and hope that one looks like the one you need. 你可以做的是使用反射来查看该类可用的方法,并希望它看起来像你需要的那个。 Try something like this: 尝试这样的事情:

try {
    Class clazz = Class.forName("android.telephony.SmsCbMessage");
    Method[] methods = clazz.getDeclaredMethods();
    for (Method m : methods) {
        Log.v("XXX", "Method found: " + m);
    }
} catch (Exception e) {
    Log.e("XXX", "Exception: " + e);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM