我有這樣的錯誤,而在Eclipse中編碼爲Android:令牌語法錯誤 「;」,期望的Java編程
語法錯誤 「;」,預計
和
多這條線上的標記
- Syntax error on token ")", { expected after
this token
- Return type for the method is missing
- Syntax error on token ".", ... expected
- Syntax error, insert ";" to complete
FieldDeclaration
而且我真的不明白爲什麼我很難確定它是什麼。 Eclipse只說出現錯誤的位置,而不是爲什麼,而其「快速修復」從不起作用。 如果有人知道如何解決這個問題plase幫我:)
package com.example.apptest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private final String defaut = "Vous devez cliquer sur le bouton « Calculer l'IMC » pour obtenir un résultat.";
private final String megaString = "Vous faites un poids parfait ! Wahou ! Trop fort ! On dirait Brad Pitt (si vous êtes un homme)/Angelina Jolie (si vous êtes une femme)/Willy (si vous êtes un orque) !";
Button envoyer = null;
Button raz = null;
EditText poids = null;
EditText taille = null;
RadioGroup group = null;
TextView result = null;
CheckBox mega = null; /*Error here with the semicolon, eclipse wants a ','*/
envoyer= (Button) findViewById(R.id.calcul); /*Long error here*/
raz = (Button) findViewById(R.id.raz);
taille = (EditText)findViewById(R.id.taille);
poids = (EditText)findViewById(R.id.poids);
mega = (CheckBox)findViewById(R.id.mega);
group = (RadioGroup)findViewById(R.id.group);
result = (TextView)findViewById(R.id.result);
// On attribue un listener adapté aux vues qui en ont besoin
envoyer.setOnClickListener(envoyerListener);
raz.setOnClickListener(razListener);
taille.addTextChangedListener(textWatcher);
poids.addTextChangedListener(textWatcher);
// Solution avec des onKey
//taille.setOnKeyListener(modificationListener);
//poids.setOnKeyListener(modificationListener);
mega.setOnClickListener(checkedListener);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
}
如果將此代碼放置在適當的位置,清潔和構建應該可以工作 –
首先嚐試Jigar的解決方案。然後嘗試在'onCreate()'內部放置'envoyer =(Button)findViewById(R.id.calcul);'並且查看它的工作原理。 –
你可以把你的全班代碼?有時Eclipse可能會表現不正常!所以不要放棄希望。在發佈的代碼中,沒有什麼看起來錯誤的(考慮R.id.calcul是有效的)。 – blackSmith