I am creating .jsp page and reiceve error about it ;
String energyv="";
int number= Integer.parseInt(request.getParameter("number"));
energyv="_"+number;
*
*
*
if (tokenNumber == 2 && found && value1.equals("")) {
value1= nextToken;
if (value1.equals(""))
found = false;
}
if (tokenNumber == 3 && found && value2.equals("")) {
value2= nextToken;
}
*
*
*
Double activeTotalLong = Double.valueOf( "value" + energyv );
*
*
*
When try to do this I recieve tomcat error;
02 Aug 2012 11:17:30,097 ERROR http-8080-4
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/PlantVisorPRO].[jsp]
– Servlet.service() for servlet jsp threw exception java.lang.NumberFormatException: For input string: “value2” at
sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224)
at java.lang.Double.valueOf(Double.java:475)
Java can create my value ( like a value2 or value1), but how can i fix string problem ?
This method takes valid numbers represented in a string.
“value2” isn’t a valid number format.
Example usages of Double.valueOf():
So, what you are trying to do is, get the value of
value2orvalue1. And what you actually wrote isSo, to solve this, there are two options:
Using arrays:
Using if-else: