Android Eclipse语法错误,请插入";}&引用;完成类主体
我是论坛的新手,我正在尝试编写一个短信应用程序。然而,我的代码中不断出现这个错误,我不知道该怎么办 这是密码Android Eclipse语法错误,请插入";}&引用;完成类主体,android,eclipse,sdk,sms,Android,Eclipse,Sdk,Sms,我是论坛的新手,我正在尝试编写一个短信应用程序。然而,我的代码中不断出现这个错误,我不知道该怎么办 这是密码 package com.sms; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.telephony.SmsManager; import android.view.View; import android.view.View.OnC
package com.sms;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
Button buttonSend;
EditText textPhoneNo;
EditText textSMS;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonSend = (Button) findViewById(R.id.buttonSend);
textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo);
textSMS = (EditText) findViewById(R.id.editTextSMS);
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String phoneNo = textPhoneNo.getText().toString();
String sms = textSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
}catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
}
}
您在结尾附近缺少一个结尾括号
public class MainActivity extends Activity {
Button buttonSend;
EditText textPhoneNo;
EditText textSMS;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonSend = (Button) findViewById(R.id.buttonSend);
textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo);
textSMS = (EditText) findViewById(R.id.editTextSMS);
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String phoneNo = textPhoneNo.getText().toString();
String sms = textSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
}catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show(); statement
e.printStackTrace();
}
}
}); //<-- here
}
}
公共类MainActivity扩展活动{
按钮发送;
编辑文本文本电话号码;
编辑文本短信;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonSend=(按钮)findViewById(R.id.buttonSend);
textPhoneNo=(EditText)findViewById(R.id.editTextPhoneNo);
textSMS=(EditText)findViewById(R.id.editTextSMS);
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
字符串phoneNo=textPhoneNo.getText().toString();
字符串sms=textSMS.getText().toString();
试一试{
SmsManager SmsManager=smsmsmanager.getDefault();
sendTextMessage(电话号码,空,短信,空,空);
Toast.makeText(getApplicationContext(),“SMS已发送!”,
Toast.LENGTH_LONG).show();
}捕获(例外e){
Toast.makeText(getApplicationContext(),
“短信失败,请稍后再试!”,
Toast.LENGTH_LONG).show();语句
e、 printStackTrace();
}
}
}); //
您忘记在OnClickListener
的定义末尾添加括号和分号);
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String phoneNo = textPhoneNo.getText().toString();
String sms = textSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
}catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});