请问这个java.lang.RuntimeException异常原因是什么
执行以下代码时,提示Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: big.txt not found!!!
java菜鸟,请问谁能指点一下这个异常的原因呢,big.txt是存在的啊。
public static Map<String,Integer> train(){
[color=#FF0000]InputStream is = new SpellCorrect().getClass().getClassLoader().getResourceAsStream("big.txt");
if(is == null){
throw new RuntimeException("big.txt not found!!!");
}
Map<String,Integer> map = new HashMap<String,Integer>();[/color]
try {
//读取语料库big.txt
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);
String s="";
while ((s = br.readLine()) != null) {
// 去掉文档中除字母外的所有符号
s = s.replaceAll("\\pP|\\pS|\\pM|\\pN|\\pC", "");
// 将文档转成小写,然后切分成单词,存在list中
s = s.toLowerCase();
String[] splits = s.split(" ");
for (int j = 0; j < splits.length; j++) {
if (!" ".equals(splits[j]) && !"".equals(splits[j]) && !splits[j].equals(null)){
if(map.containsKey(splits[j])){
Integer count=map.get(splits[j]);
map.put(splits[j], count+1);
}else{
map.put(splits[j], 1);
}
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
finally{
try{
is.close();
}catch(Exception e){
e.printStackTrace();
}
}
return map;
}
Caused by: java.lang.RuntimeException: big.txt not found!!!
java菜鸟,请问谁能指点一下这个异常的原因呢,big.txt是存在的啊。
public static Map<String,Integer> train(){
[color=#FF0000]InputStream is = new SpellCorrect().getClass().getClassLoader().getResourceAsStream("big.txt");
if(is == null){
throw new RuntimeException("big.txt not found!!!");
}
Map<String,Integer> map = new HashMap<String,Integer>();[/color]
try {
//读取语料库big.txt
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);
String s="";
while ((s = br.readLine()) != null) {
// 去掉文档中除字母外的所有符号
s = s.replaceAll("\\pP|\\pS|\\pM|\\pN|\\pC", "");
// 将文档转成小写,然后切分成单词,存在list中
s = s.toLowerCase();
String[] splits = s.split(" ");
for (int j = 0; j < splits.length; j++) {
if (!" ".equals(splits[j]) && !"".equals(splits[j]) && !splits[j].equals(null)){
if(map.containsKey(splits[j])){
Integer count=map.get(splits[j]);
map.put(splits[j], count+1);
}else{
map.put(splits[j], 1);
}
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
finally{
try{
is.close();
}catch(Exception e){
e.printStackTrace();
}
}
return map;
}
...全文
相关推荐
在Java中异常分析
#### 三、总结通过上述对几种常见的Java异常的详细介绍,我们可以看出,了解并掌握这些异常的发生原因及其解决方法对于开发健壮的应用程序至关重要。
Java程序常见异常及处理汇总
三、Java程序中几种常见的异常1. java.lang.NullPointerException(空指针异常)原因:程序中有空指针,即程序中调用了未经初始化的对象或者是不存在的对象。
Java 异常处理 | 菜鸟教程.pdf
所有的异常类都是从 java.lang.Exception 类继承来的子类。Exception 类是 Throwable 类的子类。
解决checkstyle出现的问题:Got an exception - java.lang.RuntimeException Unable to get class information for Exception
for Exception在开发过程中,我们可能会遇到使用Checkstyle时出现的异常情况,例如:“Got an exception - java.lang.RuntimeException: Unable
java.lang.runtimeexception unexpected subelement
总的来说,"java.lang.runtimeexception unexpected subelement" 是一种典型的编程异常,它提示你在处理结构化数据时遇到了意料之外的情况。


Eclipse
