Reputation: 49
I'm trying to create a class called broadcastMensajes that extends BroadcastReceiver, I'm using the code provided here: http://androidexample.com/Incomming_SMS_Broadcast_Receiver_-_Android_Example/index.php?view=article_discription&aid=62&aaid=87
Eclipse underlines almost all the code, and says "Syntax error on tokens, delete these tokens"
.
"Syntax error on token(s), misplaced construct(s)"
at the if
inside the try
The code is ok, why is this happening?
This is the code:
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);
}
}
}
Error log:
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
Upvotes: 0
Views: 1882
Reputation: 1321
add all supported imports like:
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);
}
}
}
Upvotes: 1