各位大侠
各们大侠,我是java的初学者,自己编了个实现计数功能的程序。
但现在运行老出现nullpointerexception不知道如何,请各位指点指点,谢谢!
本程序是从文件中读取一文本,文本形如the/art fulton/np country/np grand/np jury/np.....took/vbd place/nn./. 然后对art np np np ...两两计数。
import java.io.*;
import java.util.*;
class Read_f{
Read_f(){
FileReader file ;
BufferedReader in;
String t;
String str[]=new String[10000];
//读取文本
try{
file=new FileReader("tagged.txt");//读取语料库
in=new BufferedReader(file);
}
catch(FileNotFoundException e) {}
catch(IOException e) {}
//reading();
//抓取词性
int i=0;
try{ file=new FileReader("tagged.txt");//读取语料库
in=new BufferedReader(file);
String s=new String(in.readLine());
if(!(s.startsWith("/.")))
{
StringTokenizer tokenizer=new StringTokenizer(s);
//利用空格作为分隔符
while(tokenizer.hasMoreTokens())
{
t=tokenizer.nextToken();
str[i]=t.substring(t.indexOf("/")+1);
//获得一个词性并存储于数组中
i++;
}
}
else if(s.startsWith("/."))
{
in.close();
file.close();
}
}
catch(IOException exp) {}
//}
//统计
class tagged{
String s1,s2;
int count1;
}
tagged[] tagging=new tagged[10000];
for(int i1=0;i1<str.length;i++)
{ int j=0;
while(tagging[i].count1==0)
{
if(tagging[j].s1==str[i1]&&tagging[j].s2==str[i1+1])
{tagging[j].count1++;
break ;}
j++;
}
tagging[j].s1=str[i1];
tagging[j].s2=str[i1+1];
tagging[j].count1++;
}
for(int i1=0;i1<str.length;i1++)
{
//System.out.println(tagging[i1].s1+tagging[i1].s2+tagging[i1].count);
System.out.println("hello");}
}
}
public class CountTagging{
public static void main(String args[])
{ Read_f file1=new Read_f();
}
}
问题点数:0、回复次数:3Top
1 楼killme2008(为了生态平衡,请保护蛤蟆)回复于 2005-04-02 22:18:03 得分 0
你的String数组不一定完全填满,访问并未赋值的位置会引发NullPointException
用容器类吧,ArrayList或者VectorTop
2 楼piaoran11()回复于 2005-04-02 22:38:01 得分 0
好的,我试试看
谢谢:)Top
3 楼hanyaocsdn()回复于 2005-04-02 22:59:19 得分 0
upTop




