Error: cannot find symbol - Java compile error
Error: cannot find symbol - Java compile error
我已经研究了一段时间了,我确信修复就在我面前,但我只是视而不见。有人关心指出为什么我的 int i 给我一个错误?
缓存下载器class:
public static void main(String[] args) {
String strFilePath = "./version.txt";
try
{
FileInputStream fin = new FileInputStream(strFilePath);
DataInputStream din = new DataInputStream(fin);
int i = din.readInt();
System.out.println("int : " + i);
din.close();
}
catch(FileNotFoundException fe)
{
System.out.println("FileNotFoundException : " + fe);
}
catch(IOException ioe)
{
System.out.println("IOException : " + ioe);
}
}
private final int VERSION = i;
错误:
CacheDownloader.java:54: error: cannot find symbol
private final int VERSION = i;
^
symbol: variable i
location: class CacheDownloader
i 在main 中声明,private final int VERSION 在main 之外。将其移入 main 或将 i 声明为全局变量。
static int i=0;
public static void main(String[] args) {
String strFilePath = "./version.txt";
try
{
FileInputStream fin = new FileInputStream(strFilePath);
DataInputStream din = new DataInputStream(fin);
i = din.readInt();
System.out.println("int : " + i);
din.close();
}
catch(FileNotFoundException fe)
{
System.out.println("FileNotFoundException : " + fe);
}
catch(IOException ioe)
{
System.out.println("IOException : " + ioe);
}
}
private final int VERSION = i;
您必须在 try-catch
块之前声明您的 int i
。此外,您必须在 main
方法中声明常量:
public static void main(String[] args) {
String strFilePath = "./version.txt";
int i;
try
{
FileInputStream fin = new FileInputStream(strFilePath);
DataInputStream din = new DataInputStream(fin);
i = din.readInt();
System.out.println("int : " + i);
din.close();
}
catch(FileNotFoundException fe)
{
System.out.println("FileNotFoundException : " + fe);
}
catch(IOException ioe)
{
System.out.println("IOException : " + ioe);
}
final int VERSION = i;
}
我已经研究了一段时间了,我确信修复就在我面前,但我只是视而不见。有人关心指出为什么我的 int i 给我一个错误?
缓存下载器class:
public static void main(String[] args) {
String strFilePath = "./version.txt";
try
{
FileInputStream fin = new FileInputStream(strFilePath);
DataInputStream din = new DataInputStream(fin);
int i = din.readInt();
System.out.println("int : " + i);
din.close();
}
catch(FileNotFoundException fe)
{
System.out.println("FileNotFoundException : " + fe);
}
catch(IOException ioe)
{
System.out.println("IOException : " + ioe);
}
}
private final int VERSION = i;
错误:
CacheDownloader.java:54: error: cannot find symbol
private final int VERSION = i;
^
symbol: variable i
location: class CacheDownloader
i 在main 中声明,private final int VERSION 在main 之外。将其移入 main 或将 i 声明为全局变量。
static int i=0;
public static void main(String[] args) {
String strFilePath = "./version.txt";
try
{
FileInputStream fin = new FileInputStream(strFilePath);
DataInputStream din = new DataInputStream(fin);
i = din.readInt();
System.out.println("int : " + i);
din.close();
}
catch(FileNotFoundException fe)
{
System.out.println("FileNotFoundException : " + fe);
}
catch(IOException ioe)
{
System.out.println("IOException : " + ioe);
}
}
private final int VERSION = i;
您必须在 try-catch
块之前声明您的 int i
。此外,您必须在 main
方法中声明常量:
public static void main(String[] args) {
String strFilePath = "./version.txt";
int i;
try
{
FileInputStream fin = new FileInputStream(strFilePath);
DataInputStream din = new DataInputStream(fin);
i = din.readInt();
System.out.println("int : " + i);
din.close();
}
catch(FileNotFoundException fe)
{
System.out.println("FileNotFoundException : " + fe);
}
catch(IOException ioe)
{
System.out.println("IOException : " + ioe);
}
final int VERSION = i;
}