将一个类分为三个类,实现部同包之间的调用。如
文件名:DevideByMinusException.java
package org.it315;
public class DevideByMinusException extends Exception
{
public DevideByMinusException(String msg)
{
super(msg);
}
}
文件名:Test.java
package org.it315.example;
public class Test
{
public int devide(int x,int y) throws ArithmeticException,org.it315.DevideByMinusException
{
if(y < 0)
throw new org.it315.DevideByMinusException( "devisor is "+y);
int result = x / y;
return result;
}
}
文件名:TestException.java
package org.it315;
public class TestException
{
public static void main(String [] args)
{
try
{
new Test().devide(3,-1);
}
catch(ArithmeticException e)
{
System.out.println( "program is running into ArithMetic ");
}
catch(DevideByMinusException e)
{
System.out.println( "program is running into DevideByMinus ");
e.printStackTrace();
System.exit(0);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
finally
{
System.out.println( "finally ");
}
System.out.println( "program is running here! ");
}
}
这三个类原来是在一起的,所以本身的代码没有问题,只是加入了一些package语句和org.it315.前缀。
用jdk 1.5编译时出现:
D:\javawork\lesson4> javac Test.java
Test.java:4: 找不到符号
符号: 类 DevideByMinusException
位置: 软件包 org.it315
public int devide(int x,int y) throws ArithmeticException,org.it315.DevideByMinusException
^
Test.java:7: 找不到符号
符号: 类 DevideByMinusException
位置: 软件包 org.it315
throw new org.it315.DevideByMinusException( "devisor is "+y);
^
2 错误
在前面加上了包的前缀org.it315.也没有用,试了一上午,急人,请问高手问题出在哪里,我不想用import语句,只是想弄明白到底是哪的问题,万分感激
------解决方案--------------------
在 D:\javawork\lesson4> 下建一个文件夹org,在org里再建it315,把源码放进去,再试.
------解决方案--------------------