读书人

为什么不能 排序,该怎么处理

发布时间: 2012-03-15 11:50:38 作者: rapoo

为什么不能 排序
public class WordCount {
private Map m = new HashMap();

private String str = " ";

private Pattern pattern;

public WordCount(String filename) throws Exception {
BufferedReader in = new BufferedReader(new FileReader(
new File(filename)));
String s;
String[] strAry = new String[((int) new File(filename).length()) / 2];
while ((s = in.readLine()) != null)
str += s + " ";

Matcher match = Pattern.compile( "[a-zA-Z]+ ").matcher(str);
for (int i = 0;match.find();i++)
strAry[i] = match.group();
Arrays.sort(strAry);
//这里排序会抛出异常,无法排序,为什么?
}


[解决办法]
抛什么异常了? 如果是no pointer应该是因为你的数组strAry里边有些string是null
[解决办法]
数组容量过大
有许多空值
把数组容量改了
就对了

读书人网 >J2SE开发

热点推荐