簡體   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