GWT调用DOM.getElementById时,它不应该导致NullPointerException [英] GWT call to DOM.getElementById not causing a NullPointerException when it should

查看:120
本文介绍了GWT调用DOM.getElementById时,它不应该导致NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  int x = DOM.getElementById(x ).getPropertyInt( 值); 
int y = DOM.getElementById(y)。getPropertyInt(value);
int w = DOM.getElementById(w)。getPropertyInt(value);
int h = DOM.getElementById(h)。getPropertyInt(value);

每次调用 DOM.getElemendById(something)返回 null (我期望我删除它们),但调用 .getPropertyInt(value) on null的返回值不会导致NullPointerException。在开发模式下,我能够逐步浏览所有这些语句,并将x,y,w,h全部分配给零。如果我在调试器中评估Intellij评估器中的这些语句之一,则会抛出NullPointerException。



这对其他人看起来有点疯狂吗?

解决方案

文档说

 异常:try,catch,finally和用户定义的异常支持为
正常,但Throwable.getStackTrace()在
生产模式中没有有意义的支持。

注意:由Java VM隐式生成的几个基本异常,大多数
(特别是NullPointerException,StackOverflowError和OutOfMemoryError)在生产模式下不会发生
。相反,JavaScriptException是为
生成的任何隐式生成的异常。这是因为底层
JavaScript异常的性质无法可靠地映射到适当的Java
异常类型上。


There is a part of our application that does this...

int x = DOM.getElementById("x").getPropertyInt("value");
int y = DOM.getElementById("y").getPropertyInt("value");
int w = DOM.getElementById("w").getPropertyInt("value");
int h = DOM.getElementById("h").getPropertyInt("value");

Every call to DOM.getElemendById("something") returns null (which I expect as I removed them) but calling .getPropertyInt("value") on that return value of null is not causing a NullPointerException. In dev mode I am able to step through all of these statements and watch x,y,w,h all be assigned to zero. If I evaluate one of these statements in the Intellij evaluator in the debugger there is a NullPointerException thrown.

Doesn't this seem slightly insane to anybody else?

解决方案

The docs say:

Exceptions: try, catch, finally and user-defined exceptions are supported as 
normal, although Throwable.getStackTrace() is not meaningfully supported in 
production mode.

Note: Several fundamental exceptions implicitly produced by the Java VM, most 
notably NullPointerException, StackOverflowError, and OutOfMemoryError, do not 
occur in production mode as such. Instead, a JavaScriptException is produced for 
any implicitly generated exceptions. This is because the nature of the underlying
JavaScript exception cannot be reliably mapped onto the appropriate Java 
exception type.

这篇关于GWT调用DOM.getElementById时,它不应该导致NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆