2015-11-16 60 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嘗試正確縮進你的代碼,那麼你將能夠更快地發現錯誤。 –

相關問題