我得到的运行时错误是:
----jGRASP exec: javac -g Programmmm1.java
Programmmm1.java:95: error: cannot find symbol
StringTokenizer token = new StringTokenizer(infile.nextLine());
^
symbol: class StringTokenizer
location: class Programmmm1
Programmmm1.java:95: error: cannot find symbol
StringTokenizer token = new StringTokenizer(infile.nextLine());
这是我的实际细分,为什么说它找不到符号?它与我的Main有关吗?
public static void Display()throws IOException, FileNotFoundException
{
Scanner infile = new Scanner(new FileReader("G:\\DataFile.txt"));
StringTokenizer token = new StringTokenizer(infile.nextLine());
StringElement str = new StringElement();
while(token.hasMoreTokens())
{
str.setString(token.nextToken());
stringList.insert(str);
}
stringList.print();
}
答案 0 :(得分:1)
您需要在导入语句中添加它
import java.util.StringTokenizer;
<强>更新强>
public static void Display()throws IOException, FileNotFoundException
{
Scanner infile = new Scanner(new FileReader("G:\\DataFile.txt"));
StringTokenizer token = null;
String line=null;
while((line=infile.nextLine())!=null && !"".equals(line.trim()))
{
token = new StringTokenizer(line);
StringElement str = new StringElement();
while(token.hasMoreTokens())
{
str.setString(token.nextToken());
stringList.insert(str);
}
}
stringList.print();
}