`
花的世界
  • 浏览: 9212 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

null point exception

JVM 
阅读更多
空指针异常是运行期的异常,编译的时候是不会检查的,只有运行的时候才会抛出,一般情况下如果出现了空指针异常,事先你不知道会有这个异常,就说明你的程序有bug,当然就要找出这个bug,然后在变量调用之前先给它赋值,另外有一种情况,你事先知道某个操作会抛出空指针异常,常见一些非法的操作,但是又无法避免用户执行这个操作,就可以通过try,catch块捕获这个异常,然后给用户一个反馈信息,告知这个操作是非法的,因为如果你直接抛出异常的话,用户可能会看不懂,抛出了java.lang.null point exception,一般的软件使用者是看不懂的,你试想一下如果你在玩一个游戏的时候,忽然之间抛出了一大堆异常,你肯定会埋怨这个游戏垃圾,竟然会出现这样的低级错误。

java中空指针和值为空的区别
String s1 = null; // 空指针。  没有分配空间
String s2 = "";  // 值为空。   分配内存空间,存在值

s1.trim(); // 执行时程序会报空指针异常。
s2.trim(); // 执行正常。
分享到:
评论

相关推荐

    DButil.java

    private String point=null; //端口 private String userName=null; //登录帐号 private String userPass=null; //登录密码 private static DButil info = null; private DButil(){} /** * 初始化方法...

    房屋租赁系统

    } catch (Exception ex) { } System.out.println("删除成功!");// TODO Auto-generated Event stub actionPerformed() } }); } return jButton; } /** * This method initializes jButton1 * * @...

    sharepoint认证试题

    catch (Exception ex) { // 处理异常 Console.WriteLine(ex.Message); } finally { if (site != null) { site.Dispose(); } } } ``` #### 解析 在 SharePoint 开发中,正确地处理异常至关重要。上述...

    jfreechart折线图读取数据库数据的显示(mysql)

    for (Point2D.Double point : dataPoints) { series.add(point.getX(), point.getY()); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); return dataset; } ``` ...

    带注释的Bootstrap.java

    import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; ...

    重构 改善既有代码的设计

     The Starting Point 起点   The First Step in Refactoring 重构第一步   Decomposing and Redistributing the Statement Method 分解并重组slalemenl方法   Replacing the Conditional Logic on Price ...

    stdafx.h代码

    // Win resource failure exception class CUserException; // Message Box alert and stop operation class CGdiObject; // CDC drawing tool class CPen; // a pen / HPEN wrapper class CBrush; // a brush...

    kbmMemTable 7.69 for XE8

    streamed as floating point values. Notice that it will support loading older binary stream versions, but will always save in v400 which is not compatible with older software. - Added exception when ...

    DevExpress VCL v2012 vol 1.6源码、例子、帮助-part2

    Q438267 - Server Mode - Clicking a Filter Row cell in a column containing Null values throws the "Could not convert variant of type (Null) into type (OleStr)" exception Q435475 - Tabular and Layout ...

    kbmMemTable_76900

    streamed as floating point values. Notice that it will support loading older binary stream versions, but will always save in v400 which is not compatible with older software. - Added exception when ...

    c#使用命名管道实现打印调试

    textboxInformation.Location = new Point(X, Y); textboxInformation.Size = new Size(Width, Height); } void CSharpTraceForm_SizeChanged(object sender, EventArgs e) { AdjustSize(); } private ...

    C# 俄罗斯方块游戏

    catch(Exception xe) { MessageBox.Show(xe.Message); } } #region Windows 窗体设计器生成的代码 private void InitializeComponent() { this.components = new System.ComponentModel....

    仿QQ登录窗体,拉伸展开!

    } catch (Exception e) { e.printStackTrace(); } } }); } public Login(){ super("登录"); addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { do...

    java经典面试题经典中的经典啊

    对于基本图形元件,可以定义Point类存储坐标,Line类包含两个Point对象表示端点,Rectangle类包含两个Point对象表示对角线顶点,Triangle类则包含三个Point对象表示三角形的顶点。这些类可以实现相应的几何操作,如...

    ArcGIS Engine实例开发教程.doc

    catch (Exception ex) { MessageBox.Show("Error opening document: " + ex.Message); } } } private void cmdSave_Click(object sender, EventArgs e) { if (m_MapDocument != null && m_MapDocument.Is...

    swing文件拖拽

    private Point lastPoint = new Point(); private TreePath lastPath; private Timer hoverTimer; FileNode sourceNode; public DragTree() { DragSource dragSource = DragSource.getDefaultDragSource()...

    安卓开发-Android截图,圆形,Canvas.zip

    } catch (Exception e) { e.printStackTrace(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } // 清理 rootView....

    c#拼图游戏

    Point ptright = new Point(opt.X + Picsize, opt.Y); Point ptup = new Point(opt.X, opt.Y - Picsize); Point ptdown = new Point(opt.X, opt.Y + Picsize); foreach (PictureBox p in panel1.Controls) { ...

    sigfpe.rar_swap

    标题“sigfpe.rar_swap”涉及的是一个处理SIGFPE信号的交换处理器,SIGFPE是“浮点异常”(Floating Point Exception)的缩写,是Unix和类Unix操作系统中的一种信号类型。当程序在执行过程中遇到浮点运算错误,如...

    JAVA_FULL-Technical Questions and Answers.doc

    The JVM throws this exception when you try to call a method or access a field on a null object reference. To handle it, you should always check if the reference is null before attempting to use it. ...

Global site tag (gtag.js) - Google Analytics