ng.NullPointerException原因是:有空指针,有地址没赋值2.Exception in thread "main" ng.ArithmeticException: / by zero原因是除数是03.ArrayIndexOutOfBoundsException原因是:数组越界ng.NumberFormatException原因是:数字格式化有问题5.Unhandled exception type Exception原因是:没有进行异常处理6.进行国际化操作的时候遇到这样的错误:Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name Message, locale zh_CN答:因为在命令提示符中,是没有错误的解决方法是:在myeclipse中,会出现这个错误java国际化之Can't find bundle for base name1.初步学习最近在学习ResourseBundle时遇到了“Can't 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") + "!"); }}test.propertiesmsg0="Hello World"msg1="da jia hao"开始自己测试的时候:将属性文件放在bin/下也试过也不行无赖中就在google中搜索了一下终于在sun的java论坛(/thread.jspa?threadID=660477&messageID=4231534)中找到了线索下面是帖子的内容:I've solved the problem the best way possible. Basically what i've 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文件中的中文字符转化成Unicode编码方式才能正常显示中文。
解决办法:Java提供了专门的工具对Property文件进行Unicode转化,这种工具就是native2ascii,它在JDK安装环境的bin目录下。
native2ascii 工具将带有本机编码字符(非拉丁1 和非单一码字符)的文件转换成带有Unicode编码字符的文件。
假设需要转化的属性文件为:D:/src/resources.properties(含有中文字符)转化后的属性文件为:D:/classes/resources.properties(中文字符统一转化为Unicode)那么使用如下命令JAVA_HOME/bin/native2ascii -encoding GBK D:/src/resources.propertiesD:/classes/resources.properties就能将含有中文字符的属性文件转化成单一Unicode编码方式的属性文件。
中文乱码自然会被解决。
通过上面的方法我将生成的文件打开一看内容如下:ch="/u5927/u5bb6/u597d"再运行结果如下:"大家好"(2)另一种解决办法:Can't find bundle for base nameStruts2国际化异常处理这是找不到指定文件;你必须把 .properties 文件,放在与这个调用文件.java 相同的目录里;Hello.java在workspace\test\src\com\lj\guojiehua下hello_en_US.properties必须在workspace\test\src下hello_zh_CN.properties必须在workspace\test\src下其实原因是我虽然在build path 里面加了\pruway\source\source\config,但是系统编译的时候,在classes里面应该会自动产生resource_en_US.properties,可是实际情况是classes 包下面没有产生,故我删掉重加,再编译结果发现通过了。
就是说,只要你buildpath路径对了,该路径下也有resoucebudle需要的类,那么系统会自动在classes里面自动编译产生这些类的。
所以,先检查classes里,有没有生成对应的resource_en_US.properties,如果没有,那么检查build path 路径下有没有对应的properties类,如果有,那么证明系统编译没有编译完整,删掉path,重新add foler,加入,再编译,检查classes下有无。
如果都有,那么证明成功。
ng.IllegalThreadStateException解决办法:不能启动两次线程ng.NoSuchMethodError答:必须有一个 public static void main(String[] args){ //这里是入口 } 作为入口点,启动java虚拟机时虚拟机会找这个方法,如果没有就报exception in thread “main”ng.nosuchmethoderror.UnknownHostException :/原始出错程序是这样的:解答方式:import .InetAddress ;public class a{public static void main(String args[]) throws Exception {// 所有异常抛出InetAddress locAdd = null ;InetAddress remAdd = null ;locAdd = InetAddress.getLocalHost() ;// 得到本机remAdd = InetAddress.getByName("/") ;System.out.println("本机的IP地址:" + locAdd.getHostAddress()) ;System.out.println("MLDNJAVA的IP地址:"+ remAdd.getHostAddress()) ;System.out.println("本机是否可达:" + locAdd.isReachable(5000)) ;}//5000代表代数};运行后结果为:如果注释掉remAdd = InetAddress.getByName("/") ;运行结果又是这样的:上述程序的解决办法是:将remAdd = InetAddress.getByName("/") ;改成程序运行结果如下:完成实验要求,但是这里就有一个问题了,为什么去掉http//和后面的/的就运行的了呢?(2)但是对于这个极其相似的程序却可以运行出结果:import .InetAddress ;public class b {public static void main(String args[])throws Exception{InetAddress address=InetAddress.getByName("");System.out.println("ip: "+address.getHostAddress());System.out.println("host: "+address.getHostName());System.out.println("canonical host name: "+address.getCanonicalHostName());byte[] bytes=address.getAddress();for(byte b:bytes){if(b>=0)System.out.print(b);else System.out.print(256+b);}}}运行结果为:13.运行下列程序出现了这样的错误,这是线程的知识,一个线程如果启动了,再启动一个的时候就会报错:ng.IllegalThreadStateException程序如下:class thrund extends Thread{private String name;public thrund(String name){=name;}public void run(){ //线程完成的动作for(int j=0;j<4;j++){System.out.println(name+"第"+j+"个");}}};public class a {public static void main(String agrs[]){thrund th1=new thrund("线程A");//实例化一个线程对象th1.start(); //调用线程主体th1.start(); //调用线程主体}};运行结果如下:14.The public type abc must be defined in its own file这样的警告是出现在我下面这样的程序中的:所以我在百度上输入这样的问题:java程序中两个类为什么不能同时有public(其中有一个是主方法)?得到的回答是这样的:因为一个GM规定一个类中只能有一个PUBLIC 的而且源文件的名字只能和PUBLKIC 属性的类去一个名字。