public static void main(String[]args){
**exp("^[a[k][t][l]]{6}$"); //line 9**
exp("^(bEt).*(oc)$");
exp("^(bEt)$");
exp("^(a).*");
exp("bEt(oc)*");
exp("^(bEt).*");
exp [baba][bebe][bibi][bobo][bubu][fafa][fefe][fofo][fufu]
}
public static void exp(String uttryck){
int counter = 0;
File fil = new File("Walta_corpus1.txt");
Scanner sc = null;
try{
sc = new Scanner(fil);
}
catch(FileNotFoundException foo){
}
**String word = sc.next();** line 28
Pattern pattern = Pattern.compile(uttryck);
Matcher matcher = pattern.matcher(word);
while(word != null){
if(matcher.find()){
counter++;
System.out.println(word);
}
if(sc.hasNext()){
word=sc.next();
matcher = pattern.matcher(word);
}
else
word = null;
}
System.out.println(counter);
}
我需要帮助的问题是:
Exception in thread "main" java.lang.NullPointerException
at raknare.exp(raknare.java:28)
at raknare.main(raknare.java:9)
我已经尝试了很多,但没有任何真正的工作..