繁体   English   中英

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

[英]I have an inconvertible types error: cannot cast 'java.util.Objects' to 'byte[]' - This error is in createFromPdu()

代码

     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

使用对象代替:对象

Object[]  pdus = (Object[]) myBundle.get("pdus");

您可以尝试以下操作:

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

暂无
暂无

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

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