VFY:无法解决静态方法10876:安卓 [英] VFY: unable to resolve static method 10876: Android

查看:189
本文介绍了VFY:无法解决静态方法10876:安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的程序中使用SmsCbMessage.java类。这是从<一个取href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.0.1_r1/android/telephony/SmsCbMessage.java#SmsCbMessage">http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.0.1_r1/android/telephony/SmsCbMessage.java#SmsCbMessage 以下是我的计划。

I used SmsCbMessage.java class in a my program. 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.

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?

这并不是说我还包括所有必需的依赖类也使用SmsCbMessage.java类时。

Not that I also included all the required dependent classes too when using that SmsCbMessage.java class.

推荐答案

如果你的<一个源$ C ​​$ C href="https://android.googlesource.com/platform/frameworks/opt/telephony/+/jb-mr1-release/src/java/android/telephony/SmsCbMessage.java"相对=nofollow> SmsCbMessage@android.googlesource.com

您会看到类标有@隐藏属性

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

这意味着该类的是Android的实现细节是不公开的Andr​​oid API的一部分,可以更改或删除,恕不另行通知。

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.

<一个href="https://android.googlesource.com/platform/frameworks/opt/telephony/+/jb-mr1-release/src/java/android/telephony/SmsCbMessage.java"相对=nofollow> SmsCbMessage@android.googlesource.com 不热有方法公共静态SmsCbMessage createFromPdu(byte []的PDU),而<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.0.1_r1/android/telephony/SmsCbMessage.java#SmsCbMessage"相对=nofollow>您codefragment 确实有它。

SmsCbMessage@android.googlesource.com does hot have the method public static SmsCbMessage createFromPdu(byte[] pdu) while your codefragment does have it.

您试验设备确实有这个类,但没有静态方法。

Your Test-Device does have this class but without the static method.

如果你想使用这个类反正你可以添加源$ C ​​$ C到项目,并重新命名包

If you want to use the class anyway you can add the sourcecode to your project and rename the package

[更新2015年6月25日]

由于添加源来自grep的codeS到本地项目并不能解决问题,因为它有很多依赖关系(尤其是android.internal。*)

Since adding source from grepcodes to local project does not solve the problem because it has to many dependencies (especially android.internal.*)

您可以创建自己的MySmsCbMessage继承自设备SmsCbMessage类,并尝试从grep的codeS源添加缺少的功能。

you can create your own MySmsCbMessage that inherits from devices SmsCbMessage class and try to add missing functions from grepcodes source.

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;
         }
     }
}

这仍然是一个脆弱的解决办法,因为你不能舒尔其他设备将有SmsCbMessage

This is still a fragile workaround because you cannot be shure that other devices will have SmsCbMessage

这篇关于VFY:无法解决静态方法10876:安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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