您的位置:首页 > 其它

ClassNotLoadedException(NullPointerException)

2016-02-24 09:37 337 查看
try {
System.out.println( arr[(Integer) null]);

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();

}

这种方式使用数组会跑Nullpointer异常那个,因为数组中无null位置的元素。并且查看具体异常的跟踪信息(stackTrace),显示如下:

org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException: Type has not been loaded occurred while retrieving component type of array.

同理,无法使用这种方式 byte b = (Byte) null ;(同理Integer、Long等整数类型封装类)

无法将null转型为byte;

因为

 byte内部又做缓存,同样也会导致上面数组那样的空指针。

 public static Byte valueOf(byte b) {

        final int offset = 128;

        return ByteCache.cache[(int)b + offset];

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息