2015-11-16 35 views
-5

我一直在解决这个程序几个小时,尝试几种配置,并没有运气。它已经用java编写,并且有33个错误(从之前的50个降低)编译错误:“类,接口或枚举的预期”

setContentView(R.layout.activity_main); 

     sendBtn = (Button) findViewById(R.id.btnSendSMS); 
     txtphoneNo = +913331234567; 
     txtMessage = (EditText) findViewById(R.id.editText2); 

     sendBtn.setOnClickListener(new View.OnClickListener() { 
public void onClick(View view) { 
     sendSMSMessage(); 
     } 
     }); 
     } 
protected void sendSMSMessage() { 
     Log.i("Send SMS", ""); 
     String phoneNo = txtphoneNo.getText().toString(); 
     String message = txtMessage.getText().toString(); 

     try { 
     SmsManager smsManager = SmsManager.getDefault(); 
     smsManager.sendTextMessage(phoneNo, null, message, null, null); 
     Toast.makeText(getApplicationContext(), "SMS sent.", Toast.LENGTH_LONG).show(); 
     } 

     catch (Exception e) { 
     Toast.makeText(getApplicationContext(), "SMS faild, please try again.", Toast.LENGTH_LONG).show(); 
     e.printStackTrace(); 
     } 
     } 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
     } 
     } 
+5

请告诉我这不是你的完整代码 – Reimeus

+1

很难调试这些代码片段。你能告诉我们你的错误的行号吗? – Sreekar

+1

当你试图把东西放在错误的地方时,你会得到这条消息。我想我们需要看到这个全班。 –

回答

1

你的问题是你有一个额外的大括号('}')的地方。这是关闭类,然后编译器然后寻找另一个类,接口或枚举定义

+0

是的,我认为额外的大括号只是在保护void sendSMSMessage() – Sreekar

+0

上方嗯,我删除了两个大括号,错误减少到19 –

+1

@Adnansaram尝试正确缩进你的代码,那么你将能够更快地发现错误。 –

相关问题