我有一个私有访问错误,与变量“totalFloat”有关。但是我一直在引用和使用同一类中的方法而没有这个问题。
在这种情况下,是否存在解决私有访问错误的一般方法?
public static void writeHtmlFile() {
double contentsChangeDraw;
String ChangeDrawer = "ChangeFloat.html";
try {
PrintWriter outputStream = new PrintWriter(ChangeDrawer);
contentsChangeDraw=cd.getTotalFloat(totalFloat);
// totalFloat has private access in ChangeDrawer, which means I am
// unable to use the method to calculate the array that needs to be written
outputStream.println(contentsChangeDraw);
outputStream.close();
System.out.println("The contents of the ChangeDrawer have been written to a file");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
我打赌totalFloat
有这样的声明:
private int totalFloat; // or double, or boolean, or something else
您无法从静态方法访问它,因为它是成员变量。做到这一点
private static int totalFloat; // or double, or boolean, or something else
访问它(或将方法writeHtmlFile()
更改为不是静态的)。