2014-05-07 176 views
1

運行時的錯誤,我得到的是:運行時錯誤。請給我認識什麼我做錯了

----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(); 
    } 

回答

1

你需要在你的import語句

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(); 
} 
+0

你不知道有多難,我在我自己現在笑添加此!非常感謝! – user3604953

+0

@ user3604953不客氣。 – Prabhakaran

+0

你知道爲什麼當我運行它時,它只顯示我的數據文件中的名字? – user3604953