简体   繁体   中英

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

code

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


    }
}
}

manifest

<?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>

I have an error in createFormatPdu()

red line is byte my error is

Error inconvertible types; cannot cast 'java.util.Objects' to 'byte[]'
This error is in createFromPdu()

My SDK version is 8

使用对象代替:对象

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

您可以尝试以下操作:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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