java - 我有一个不可转换的类型错误: cannot cast 'java.util.Objects' to 'byte[]' - This error is in createFromPdu()

标签 java android compiler-errors


     package com.yasharkhosravi.applicationhack;

     import android.content.BroadcastReceiver;
      import android.content.Context;
      import android.content.Intent;
        import android.os.Bundle;
         import android.telephony.SmsMessage;

         import java.util.Objects;

        public class SMSReceive extends BroadcastReceiver {
       public SMSReceive() {
}

@Override
public void onReceive(Context context, Intent intent) {
    SmsMessage[] msgs = null ;
    Bundle bundle = intent.getExtras();
    if (bundle != null)
    {
        Objects[] pdus = (Objects[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];
        String s = "";
        for (int i = 0 ; i<msgs.length ; i++)
        {
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
            if(i==0) {
                s += msgs[i].getOriginatingAddress().toString();
                s += "\n";
            }
            s +=msgs[i].getMessageBody().toString();
        }


    }
}
}

表现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yasharkhosravi.applicationhack" >

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity android:name=".MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

                      <category                                                      android:name="android.intent.category.LAUNCHER"     />
        </intent-filter>
    </activity>

    <receiver
        android:name=".SMSReceive"
        android:enabled="true"
        android:exported="true" >
    </receiver>
</application>

   </manifest>

我的createFormatPdu()错误

红线是字节
我的错误是

错误不可转换类型;无法将“java.util.Objects”转换为“byte []”
此错误在createFromPdu()

我的SDK版本是8

最佳答案

您可以尝试以下方法:

Objects[] pdus = (Objects[]) bundle.get("pdus");  (use Object replace Objects)

关于java - 我有一个不可转换的类型错误: cannot cast 'java.util.Objects' to 'byte[]' - This error is in createFromPdu(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33711823/

相关文章:

Android - 基本下载进度文本

android - 将外部 xml 文件用于自定义 ListView 适配器?

android - 钛 android 中的 tableview 子项中的标签文本未更新。但在 IOS 中有效

c++ - 在循环中加入线程 - 转换错误

c++11 - C++ 11编译失败, undefined reference ,另一个类内部的显式模板类实例化

java - 在oracle中使用什么来解析xml文件

java - Java中void方法调用

java - 为什么这个打印是NULL?

java - Mockito:如何验证来自另一个单例类的单例类的方法调用

scala - 下划线 "class needs to be abstract since method is not defined"错误