对于参数类型 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
}
}
);
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
}
}
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来
entry
是一个EditText
对象......你不能将其相乘。我将做出一个有根据的猜测,您想要将
EditText
中的内容相乘。查看javadocs,您需要使用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
It would appear that
entry
is anEditText
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 withentry.getText().toString()
, and convert it to a numeric type (provided the text represents a numeric type).(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