Java中常见错误和异常解决方法.doc
文本预览下载声明
1.java.lang.NullPointerException
原因是:有空指针,有地址没赋值
2.Exception in thread main java.lang.ArithmeticException: / by zero
原因是除数是0
3.ArrayIndexOutOfBoundsException
原因是:数组越界
4.java.lang.NumberFormatException
原因是:数字格式化有问题
5、Unhandled exception type Exception
原因是:没有进行异常处理
6.进行国际化操作的时候遇到这样的错误:Exception in thread main java.util.MissingResourceException: Cant find bundle for base name Message, locale zh_CN
答:因为在命令提示符中,是没有错误的
解决方法是:在myeclipse中,会出现这个错误java国际化之Cant find bundle for base name
分类: JAVA2011-02-22 21:17231人阅读评论(0)收藏举报
1.初步学习
最近在学习ResourseBundle时遇到了“Cant find bundle for base name ”这个错误搞了很久才解决了。原因就是类路径问题要将属性文件放在类路径中!百度里很多都是教程但没有涉及到解决方法! 2.中文显示:
测试文件
java 代码package com.lht.ResourseBundleStudy;import java.util.ResourceBundle;public class ResourseBundleDemo { public static void main(String[] args) { ResourceBundle resource = ResourceBundle.getBundle(test); System.out.print(resource.getString(msg0) + !); System.out.println(resource.getString(msg1) + !); }}
perties
msg0=Hello Worldmsg1=da jia hao
开始自己测试的时候:将属性文件放在bin/下也试过也不行无赖中就在google中搜索了一下终于在sun的java论坛
(/thread.jspa?threadID=660477messageID=4231534)中找到了线索下面是帖子的内容:
Ive solved the problem the best way possible. Basically what ive done is added a new class folder named config to the project home dir. Then i added this classfolder to the classpath in project properties. After doing all of this you only need to reference the properties file by Email.
Hope this helps anyone else who is having similiar problems.
基本意思就是在src下建立classes(名字无所谓)文件夹将属性文件存放在下面,然后将这个文件夹加入类路径中!运行就可以了:
加入类路径的方法:你的工程文件夹-properties-选择Libraries选项卡-Add Class Folder将刚才建立的文件夹加入就可以了!
结果如下:
Hello World!da jia hao;!
2.中文显示
在classes目录下建立message_CH.properties内容如下:
ms0=大家好
同样用上面的测试文件!
结果如下:?ó????!
乱码怎么回事啊!
在百度里搜索后找到了答案有以为网友写的很清楚:/3885062.html
下面引用如下:
原理
Property文件中,使用的编码方式根据机器本身的设置可能是GBK或者UTF-8。而在Java程序中读取Property文件的时候使用的是Unicode编码方式,这种编码方式不同会导致中文乱码。因此需要将Property文件中的中文字符转
显示全部