jsp一些异常总结(转自校内--2008-11-26 20:01 (分类:默认分类))
一些异常的总结(不断的总结,加入)
java.lang.ClassCastException: java.lang.String
java.lang.Object
|
+----java.lang.Throwable
|
+----java.lang.Exception
|
+----java.lang.RuntimeException
|
+----java.lang.ClassCastException
public class ClassCastException extends RuntimeException
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException:
Object x = new Integer(0);
System.out.println((String)x);
ClassCastException()
Object o="l am a student";
String s=(String)o;
System.out.println(s);
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 14
at java.lang.String.getChars(Unknown Source)
at java.io.BufferedWriter.write(Unknown Source)
at package1.file2.main
BufferedWriter output=new BufferedWriter(new FileWriter("D:\\bb.txt"));
String line ;
output.write("pan jun", 0, 14);
output.close();
这里的异常是应为长度超过了7,如果小于七是没问题的
还有就是一定要output.close(),否则就不能写进去了
java.lang.UnsupportedClassVersionError
Exception in thread "main" java.lang.UnsupportedClassVersionError: Math (Unsuppo
rted major.minor version 50.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass
你编译和执行用了不同的jdk版本
你可以看看你的path中java是在什么地方,使用相同的版本就好了