http 请求后 GWT 中未捕获的异常
我有一个使用 GWT 创建的 Web 应用程序,它通过对 php 文件的 http 请求与服务器交互。我向以下 php 文件发出请求: http:// /localhost/bibliotheek/php/addUser.php?username=username.test2&group=test&admin=false&password=&topadmin=false
当我在托管模式下执行此操作时(因此在编译后)我得到以下异常:
未捕获的异常:[异常... “'java.lang.NumberFormatException:对于 调用方法时输入字符串:“”': [nsIDOMEventListener::handleEvent]” ns结果:“0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)” 位置:“JS框架:: chrome://firebug/content/spy.js:: callPageHandler :: 第 744 行数据: 没有]
第 0 行
我仅在该请求中得到此异常,而在其他请求中则没有。我使用以下代码发出请求:
protected void addUserToTheDatabase(String[] data) {
String file = "addUser.php?username=" + data[0] + "&group=" + data[1] + "&admin=" +
data[2] + "&password=" + data[3] + "&topadmin=" + data[4];
request object = new request();
object.getMessageXml(file, "GET", "null", new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
new UserInterface.notification(BibPhp.error.INTERNET_CONNECTION);
caught.getMessage();
}
@Override
public void onSuccess(String result) {
if(Integer.parseInt(result) == 0) {
new UserInterface.notification("Deze gebruikersnaam is reeds in gebruik.");
}
else {
new UserInterface.notification("Gebruiker toegevoegd.");
}
new add(false);
}
});
}
我不知道我做错了什么,因为所有其他请求或完全相同,只是针对其他文件。 php 文件不会生成响应,因此会产生任何影响。
还有其他人遇到过这个问题或有什么建议吗?
提前致谢。
I have an web application created with GWT which interacts with a server via http requests to php files. I make a request to the following php file:
http://localhost/bibliotheek/php/addUser.php?username=username.test2&group=test&admin=false&password=&topadmin=false
When I do this in hosted mode (so after compiling) I get the following exception:
uncaught exception: [Exception...
"'java.lang.NumberFormatException: For
input string: ""' when calling method:
[nsIDOMEventListener::handleEvent]"
nsresult: "0x8057001c
(NS_ERROR_XPC_JS_THREW_JS_OBJECT)"
location: "JS frame ::
chrome://firebug/content/spy.js ::
callPageHandler :: line 744" data:
no]Line 0
I get this exception only with this request, not with other requests. I make the request with the following code:
protected void addUserToTheDatabase(String[] data) {
String file = "addUser.php?username=" + data[0] + "&group=" + data[1] + "&admin=" +
data[2] + "&password=" + data[3] + "&topadmin=" + data[4];
request object = new request();
object.getMessageXml(file, "GET", "null", new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
new UserInterface.notification(BibPhp.error.INTERNET_CONNECTION);
caught.getMessage();
}
@Override
public void onSuccess(String result) {
if(Integer.parseInt(result) == 0) {
new UserInterface.notification("Deze gebruikersnaam is reeds in gebruik.");
}
else {
new UserInterface.notification("Gebruiker toegevoegd.");
}
new add(false);
}
});
}
I have no idea what I do wrong because all the other requests or exact the same, just to an other file. The php file doesn't generate a a response, so that can make any influence.
Any other people that experienced this problem or any suggestions?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的 onSuccess 方法中,您执行 Integer.parseInt(result) 。如果结果的值为“”,您可能会得到上述异常。我会确认 result 的值实际上是一个数字而不是一个空字符串。您还可以在 parseInt 调用周围放置一个 try ... catch 来捕获 NumberFormatException 并通知用户。
In your onSuccess method you do an Integer.parseInt(result). If the value of result is "" you might get the above exception. I would confirm that the value of result is actually a number and not an empty string. You can also put a try ... catch around the parseInt call to catch the NumberFormatException and notify the user.