我正在開發第一個android應用程序,它由一個百分比計算器組成。有兩個文本框用於輸入數字,一個文本視圖,顯示結果和一個按鈕。當我運行該應用程序時,它給了我關於類的這些錯誤。我去了android.develpers網站查找按鈕文檔,似乎是正確的。但是,我不知道問題是什麼。這是我實施的代碼。開發第一個android應用程序的錯誤
//calculator variables
TextView totalTxtView;
EditText numberTxt;
EditText percentTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//calculator code starts here ------------------//
//references
percentTxt = (EditText) findViewById(R.id.percentTxt);
numberTxt = (EditText) findViewById(R.id.numberTxt);
totalTxtView = (TextView) findViewById(R.id.totalTxtView);
Button button = (Button) findViewById(R.id.calcButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
float percent = float.parseFloat(percentTxt.getText().toString());
float number = float.parseFloat(numberTxt.getText().toString());
float result = numbrer * (percent * 0.10);
totalTxtView.setText(Float.toString(result));
}
});
這是錯誤日誌
Error:(41, 39) error: class expected
Error:(41, 49) error: ';' expected
Error:(41, 81) error: ';' expected
Error:(42, 38) error: class expected
Error:(42, 48) error: ';' expected
Error:(42, 79) error: ';' expected
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 8.936 secs
Information:7 errors
Information:0 warnings
Information:See complete output in console
enter code here
任何幫助讚賞
'float result = numbrer *(percent * 0.10);'---你在這行看起來有一個錯字 – LiXie