gpt4 book ai didi

android - token 语法错误,构造放置错误?

转载 作者:行者123 更新时间:2023-12-03 08:29:08 26 4
gpt4 key购买 nike

我正在尝试创建一个称为broadcastMensajes的类,该类扩展了BroadcastReceiver,使用的是此处提供的代码:http://androidexample.com/Incomming_SMS_Broadcast_Receiver_-_Android_Example/index.php?view=article_discription&aid=62&aaid=87

Eclipse几乎在所有代码下划线,并说"Syntax error on tokens, delete these tokens"
"Syntax error on token(s), misplaced construct(s)"if处的try
代码还可以,为什么会这样?

这是代码:

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

public class broadcastMensajes extends BroadcastReceiver {


    AccionesExecuter Ejecutor = new AccionesExecuter();
    final SmsManager smsManager = SmsManager.getDefault();
     
    @Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
     

        // Retrieves a map of extended data from the intent.
        final Bundle bundle = intent.getExtras();
 
        try {
             
            if (bundle != null) {
                 
                final Object[] pdusObj = (Object[]) bundle.get("pdus");
                 
                for (int i = 0; i < pdusObj.length; i++) {
                     
                    SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                    String phoneNumber = currentMessage.getDisplayOriginatingAddress();
                     
                    String senderNum = phoneNumber;
                    String message = currentMessage.getDisplayMessageBody();
                     
                } // end for loop
              } // bundle is null
 
        } catch (Exception e) {
            Log.e("SmsReceiver", "Exception smsReceiver" + e);
             
        }
    }   
}

错误日志:
Description Resource    Path    Location    Type
Syntax error on token(s), misplaced construct(s) broadcastMensajes.java /Actions/src/com/nahue/actions line 27 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 14 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 15 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 16 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 20 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 27 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 29 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 31 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 31 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 33 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 34 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 36 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 37 Java Problem
Syntax error on tokens, delete these tokens broadcastMensajes.java /Actions/src/com/nahue/actions line 43 Java Problem
Syntax error, insert ";" to complete Statement broadcastMensajes.java /Actions/src/com/nahue/actions line 43 Java Problem
Syntax error, insert "}" to complete Block broadcastMensajes.java /Actions/src/com/nahue/actions line 43 Java Problem
Syntax error, insert "}" to complete ClassBody broadcastMensajes.java /Actions/src/com/nahue/actions line 18 Java Problem
Syntax error, insert "}" to complete MethodBody broadcastMensajes.java /Actions/src/com/nahue/actions line 18 Java Problem
Syntax error, insert "else Statement" to complete IfStatement broadcastMensajes.java /Actions/src/com/nahue/actions line 43 Java Problem

最佳答案

添加所有受支持的导入,例如:

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

public class BroadcastMensajes extends BroadcastReceiver {
AccionesExecuter Ejecutor = new AccionesExecuter();
final SmsManager smsManager = SmsManager.getDefault();

@Override
public void onReceive(Context context, Intent intent) {
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();

try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody();
} // end for loop
} // bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" + e);
}
}
}

关于android - token 语法错误,构造放置错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27665139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com