【发布时间】:2016-11-28 06:41:10
【问题描述】:
我尝试运行代码,但收到错误“无法将点解析为变量”。为什么我会收到此错误,请尝试自己运行代码并分享您得到的输出。谢谢。
public class ReferenceMystery1 {
public static void main(String[] args) {
int a = 7;
int b = 9;
Point p1 = new Point(2,2);
Point p2 = new Point(2,2);
addToXTwice(a, p1);
System.out.println(a + " " + b + " " + p1.x + " " + p2.x);
addToXTwice(b, p2);
System.out.println(a + " " + b + " " + p1.x + " " + p2.x);
}
public static void addToXTwice(int a, Point b) {
a = a + a;
p1.x = a;
System.out.println(a + " " + p1.x);
}
}
【问题讨论】:
-
使用
b.x而不是p1.x,因为在这个函数范围addToXTwice(int a, Point b)中没有p1 -
我们也会得到同样的错误,你在哪里导入了
Point? -
共享整个堆栈跟踪。也分享Point Class的全部细节。是你写的课吗?还是 java.awt.Point 还是 org.openqa.selenium.Point?