How to fix NumberFormatException for input string "0.40" [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
i am trying to convert string value to long for further processing but this error occurs everytime
13-Feb-2019 13:15:35.593 SEVERE [http-nio-8084-exec-570] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service()
java.lang.NumberFormatException: For input string: "0.40"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)

You are trying to store the value 0.4 in a long. Long doesn't support floating point values, so you have to use either float or double.
Exceptions like this one can be handled in your code using try and catch.

Related

How can i prevent the error java.lang.NumberFormatException: For input string: "72" [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
when i execute the program i get
Exception in thread "main" java.lang.NumberFormatException: For input string: "72"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at java.base/java.lang.Integer.valueOf(Integer.java:957)
at Convert.main(Convert.java:13)
How can i solve this error
At Convert.java:13 You use Integer.valueOf(bb, 6) which means the input string must represent a number in base 6 (radix). 7 is not a valid digit for such a representation, hence the exception. (In base 6, digits must be 0-5 inclusive)
https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#valueOf(java.lang.String,%20int)
public static void main(String[] args) {
System.out.println(Integer.parseInt("72"));
}
This codes prints 72 correctly, does it help if you compare it to your own code ?

DateTimeParseException thrown for unknown reason [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Here is the full error line:
java.time.format.DateTimeParseexception: Text '01-Jan-2020' could not be parsed at index 0
Here is the code I am using that throws the error:
val DATETIME_FORMAT = DateTimeFormatter.ofPattern("d-MMM-yyyy").withZone(ZoneId.of("UTC"))
val parsedTime = DATETIME_FORMAT.parse(input)
the input variable is '01-Jan-2020' as seen in the error line.
I have looked at many similar questions to this one but it's not the expected solution. Can anybody enlighten me on how to solve this problem?
You have to set Locale as second parameter ofPattern method, look below (working code in java)
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy", Locale.ENGLISH).withZone(ZoneId.of("UTC"));
var parsedTime = dateTimeFormatter.parse("01-Jan-2020");

A variable with datatype as Double with value '0.0' not appearing in JSON response [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
The response to a REST web service has a field of type Double. If its value is '0.0' that field is not appearing in JSON response
Try using #JsonInclude(Include.ALWAYS) as javadoc says
property is to be always included, independent of value of the
property

How would you display each element of an array that is returned from another method in Java? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
For example, I have my main method as well as the method returnOdds(original), that returns the integer array "odd"
How would I print the elements of this array in the main method? With a for loop?
A for loop would work. If you don't care about the format, though, a simpler solution might be to use Arrays.toString, which will convert in the form "[elem1, elem2, ..., elemn]".
"With a for loop?"
answer : "yes"

sql BIT to Java [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
My sqlserver table has a column designed as a BIT datatype. It has values 1 and 0s
Then in my Java code, I do
result = new ArrayList
result.add( (Boolean)(rs.getBoolean("columnName")));
Then when I read the value from the list - it shows as Long.
According to everything I find, it says hat a BIT datatype is supposed to map to boolean.
Why does it come as Long?
What can be done to fix this?
You can call getBoolean directly and let it take care of all the casting/coverting:
result.add(rs.getBoolean("columnName"));

Categories