我不确定这里发生了什么,但这里是我遇到问题的一部分(还有其他几个,但我认为如果可以的话弄清楚这里的逻辑我可以在其他地方应用)。 我最近有一个问题,我在使用点,但不能得到小数,所以,as suggested,我切换到point2D允许双打。由于切换我得到的错误,我似乎无法理解如何解决,因为我没有看到原因(我知道改变到point2D触发它,但我看不到连接)。运算符*未定义为参数类型double,Point2D.Double
我有以下代码:
Double x_data = (Double) data.get(k);
for (int c = 0; c <= 100; c++) { //the c variable caps the percent
double percent = roundTwoDecimals(c*.01);
double value1 =(sum - percent * x_data);
数据的Point2D(这我铸造将翻一番,总和变量我送的这个方法的确是一个整数,但我的列表在日食中,我在'percent * x_data'下面看到了可怕的红色下划线,我搜索了一下,发现这个错误通常是由于某个人试图乘以一个字符串或其他东西引起的,但我相当肯定这些都是双打。现在得到以下错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The operator * is undefined for the argument type(s) double, Point2D.Double
The operator * is undefined for the argument type(s) double, Point2D.Double
Syntax error, insert ")" to complete ArgumentList
The operator * is undefined for the argument type(s) double, Point2D.Double
据我所知,涉及这个过程的事情要么是双重的,要么是双倍的,所以我不确定为什么Point2D会涉及这些运营商。
我也有一个,限制了小数位的方法:
static double roundTwoDecimals(double d) {
DecimalFormat twoDForm = new DecimalFormat("#.###");
return Double.valueOf(twoDForm.format(d));
但Double.valueOf不是一个选项了,所以我上的错误(错误的Point2D)(绕过它,我只是现在返回d而不限制小数)。
请帮忙。我认为point2D没有问题,但我必须在结构上做错了什么。
由于
从我在异常中看到的内容中,您试图使用'*'运算符将'double'类型的变量与'Point2D.Double'类型相乘。 Java VM告诉你它不知道该怎么做。也许你已经导入了'Point2D.Double',它覆盖了'Double',它是本地类型'double'的对象版本? – len 2012-03-26 16:47:41