gpt4 book ai didi

java.lang.NumberFormatException : For input string: "add" 异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:18:19 26 4
gpt4 key购买 nike

你好,我用奇数或偶数制作了一个网络服务,当我在 netbeans 中为该网络服务制作客户端时,我遇到了这个错误。这里的网络服务:

@WebService(serviceName = "Par_Impar")
public class Par_Impar {

/**
* Web service operation
*/
@WebMethod(operationName = "operation")
public String operation(@WebParam(name = "val") int val) {
if(val%2!=0){
//daca reminder-ul nu este 0 este impar
return("IMPAR");
}
else {
//daca reminder-ul este 0 atunci este par
return("PAR");
}
}

}

index.jsp:

<html>
<head>
<title>PAGINA JSP</title>
</head>
<body>
<form action="action.jsp" method="post"<br/>
Introdu numarul :<input type="text" name="nr"/><br/>
<input type="submit" value="Testeaza"/>
</form>

</body>

action.jsp :

<%-- 
Document : action
Created on : Apr 27, 2013, 5:28:45 PM
Author : ARB
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%-- start web service invocation --%><hr/>
<%
String add=request.getParameter("numar");
int aa=Integer.parseInt("add");
try {
mypack.ParImpar_Service service = new mypack.ParImpar_Service();
mypack.ParImpar port = service.getParImparPort();
// TODO initialize WS operation arguments here
int val=aa;
// TODO process result here
java.lang.String result = port.operation(aa);
out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
%>
<%-- end web service invocation --%><hr/>
</body>
</html>

请帮帮我。谢谢!

最佳答案

int aa=Integer.parseInt("add");

上面一行应该是:

int aa=Integer.parseInt(add);

parseInt

Parses the string argument as a signed integer in the radix specifiedby the second argument. The characters in the string must all bedigits of the specified radix (as determined by whetherCharacter.digit(char, int) returns a nonnegative value), except thatthe first character may be an ASCII minus sign '-' ('\u002D') toindicate a negative value or an ASCII plus sign '+' ('\u002B') toindicate a positive value. The resulting integer value is returned.

An exception of type NumberFormatException is thrown if any of thefollowing situations occurs:

  1. The first argument is null or is a string of length zero.

  2. The radix is either smaller than Character.MIN_RADIX or larger thanCharacter.MAX_RADIX.

  3. Any character of the string is not a digit of the specified radix,except that the first character may be a minus sign '-' ('\u002D')or plus sign '+' ('\u002B') provided that the string is longer thanlength 1.

  4. The value represented by the string is not a value of type int.

关于java.lang.NumberFormatException : For input string: "add" 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16254001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com