[問題] 關於去除文章中重複值
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.StringTokenizer;
public class readtxt {
static int offset=0;
public static void main (String[] arg) throws IOException {
int i = 2219701;
String[] str = null ;
FileReader file = new FileReader("C:/AppServ/www/gogo/content/"+i+".txt");
BufferedReader bfr = new BufferedReader(file);
StringTokenizer st = null;
while (bfr.ready()) {
st = new StringTokenizer(bfr.readLine());
while( st.hasMoreTokens() ){
//System.out.println( st.nextToken() );
offset++;
str[offset]=st.nextToken();
}
}
for (String k : deleteSameNumber(str)) {
System.out.print(k+" ");
}
}
public static String[] deleteSameNumber(String[] ary) {
String [] temp = new String[ary.length];
Arrays.sort(ary);
int j = 0;
for (int i=0; i<ary.length; i++) {
if ( i != 0 && ary[i] .equals(temp[j-1])) {
j--;
}
temp[j]=ary[i];
j++;
}
String[] temp2 = new String[j];
for (int k=0; k < j; k++) {
temp2[k] = temp[k];
}
return temp2;
}
}
想請問我編譯的時候都會出現以下訊息
Exception in thread "main" java.lang.NullPointerException
at readtxt.main(readtxt.java:20)
是什麼問題?
以爬過文不過沒相關解答
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.141.32.53
→
02/11 19:38, , 1F
02/11 19:38, 1F
→
02/11 19:39, , 2F
02/11 19:39, 2F
→
02/11 19:42, , 3F
02/11 19:42, 3F
→
02/11 19:50, , 4F
02/11 19:50, 4F
→
02/11 19:55, , 5F
02/11 19:55, 5F
→
02/11 19:55, , 6F
02/11 19:55, 6F
→
02/11 19:57, , 7F
02/11 19:57, 7F
→
02/11 20:11, , 8F
02/11 20:11, 8F
→
02/11 20:28, , 9F
02/11 20:28, 9F