0

我得到的价值是:

String responseTime = request.getParameter("rt");

rt文本框的名称在哪里。

我想要整数/浮点值responseTime。但是当我编写以下代码时:

int rTime = Integer.parseInt(responseTime);

或者

int rTime = Integer.parseInt(responseTime.toString());

我得到这些错误中的任何一个

java.lang.NumberFormatException;
java.lang.NullPointerException;

如何解决这个问题?

4

1 回答 1

0

responseTime您的变量似乎为空。所以在第一种情况下

int rTime = Integer.parseInt(responseTime);

你得到NumberFormatException了,因为 null 不能被解析为整数。

对于第二种情况

int rTime = Integer.parseInt(responseTime.toString());

你得到NPE是因为你调用toStringnull。

因此,请确保正确传递变量并仔细检查请求中变量的名称。

于 2013-02-26T07:20:46.990 回答