2016-11-12 39 views
1

我正在開發第一個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 

任何幫助讚賞

+0

'float result = numbrer *(p​​ercent * 0.10);'---你在這行看起來有一個錯字 – LiXie

回答

0

之前,你看太深入的調試,我相信你已經有了一個錯字。

如果我正確理解您的邏輯,result應該是數字number作爲由percentage給出的百分比。然後,你實際上應該更換:

float result = numbrer * (percent * 0.10); 

隨着

float result = number * (percent * 0.01); 

如果沒有,那麼糾正你的錯字到:

float result = number * (percent * 0.10); 

然後更新您的程序,並看看會發生什麼。

+0

謝謝,這看起來像一個愚蠢的問題,但我試着穿過調試器,它指出我的課程錯誤。它完全把我扔了。調試器無法更準確地指出錯誤。糾正錯誤(錯字)後仍然不起作用的 – miatech

+0

。運行應用程序時出現7個錯誤。他們都是。我是否需要導入任何課程? – miatech

相關問題