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)
私はたくさん試しましたが、実際には何もうまくいきません..