【问题标题】:The operator * is undefined for the argument type(s) double, EditText对于参数类型 double、EditText,运算符 * 未定义
【发布时间】:2012-03-03 12:32:12
【问题描述】:

我真的不确定为什么会收到此错误。这可能很简单,但我是新手。

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
            }
        }

    );

【问题讨论】:

  • onClick方法接收参数的原因是什么。

标签: java android operators


【解决方案1】:

看起来entry 是一个EditText 对象......你不能乘以它。

我将做出一个有根据的猜测,您想将EditTextin 相乘。查看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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-26
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 2014-06-02
    • 2021-01-29
    • 1970-01-01
    相关资源
    最近更新 更多