运算符*未定义的参数类型(S)双,的EditText [英] The operator * is undefined for the argument type(s) double, EditText
问题描述
我真的不知道为什么我得到这个错误。这也可能是简单的东西,但我是新来的这一点。
最后按钮计算=(按钮)findViewById(R.id.calculate);
calculate.setOnClickListener(新View.OnClickListener(){
//实施OnClickListener回调
私人无效的onClick(按钮计算){
双周长= 2 *(Math.PI *入口); //错误在这条线
System.out.print(周长); } 公共无效的onClick(视图v){
// TODO自动生成方法存根
}
} );
这样看来,输入
是的EditText
对象...你不能乘以。
我要做出一个受过教育的猜测要乘什么的在的是的EditText
。综观的javadoc,你需要获得的文字 entry.getText()。的toString()
,并将其转换为数字类型(提供的文本再presents数字型)。
双myInputDouble = Double.parseDouble(entry.getText()的toString());
(或的Integer.parseInt()
如果这是你期待什么)
<一个href=\"http://developer.android.com/reference/android/widget/EditText.html\">http://developer.android.com/reference/android/widget/EditText.html
<一href=\"http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html\">http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html
<一href=\"http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html\">http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html
I'm really not sure why I get this error. It's probably something simple but I'm new to this.
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
}
}
);
It would appear that entry
is an EditText
object ... you can't multiply that.
I'm going to make an educated guess that you want to multiply what's in that EditText
. Looking at the javadocs, You need to get the text with entry.getText().toString()
, and convert it to a numeric type (provided the text represents a numeric type).
double myInputDouble = Double.parseDouble(entry.getText().toString());
(or Integer.parseInt()
if that's what you're expecting)
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
这篇关于运算符*未定义的参数类型(S)双,的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!