2012-02-11 105 views
-1

我真的不確定爲什麼會出現此錯誤。這可能很簡單,但我是新手。運算符*未定義爲參數類型double,EditText

final Button calculate = (Button) findViewById(R.id.calculate); 
calculate.setOnClickListener(new View.OnClickListener() { 
     // Implement the OnClickListener callback  
     private void onClick(Button calculate) { 
       double perimeter = 2 * (Math.PI * entry); //error on this line 
       System.out.print(perimeter); 

       } 

     public void onClick(View v) { 
     // TODO Auto-generated method stub 
      } 
     } 

    ); 
+0

什麼是項的類型? – perreal 2012-02-11 05:02:56

+0

'onClick'方法接收參數的原因是什麼? – Mahesh 2012-02-11 05:03:22

回答

5

這樣看來,entryEditText對象...你不能乘上。

我打算做一個有根據的猜測,你想要乘以EditText。查看javadocs,您需要獲取entry.getText().toString()的文本,並將其轉換爲數字類型(假設文本表示數字類型)。

double myInputDouble = Double.parseDouble(entry.getText().toString()); 

(或Integer.parseInt()如果這就是你期待什麼)

http://developer.android.com/reference/android/widget/EditText.html
http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html
http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html

相關問題