FAQ Database Discussion Community


Illegal Number Format Exception in Java

jlabel,numberformatexception
I have this code, which pulls in a double value from an external method call, converts it into a String and then displays it in a JLabel. My problem is that sometimes the value might display: 1.95000000000000001, and I want to reduce that to 1.95. When I run the application,...

Android - NumberFormatException Issue

android,android-fragments,number-formatting,numberformatexception
I'm having an issue with the following code when entering in a value with a decimal point. It doesn't matter if I enter in 56. or 56.3 or 56.345, it still makes the app crash and throws the NumberFormatException. Here is the code where the exception is being thrown: private...

Get java.lang.NumberFormatException for DriverManager.getConnection

java,mysql,scala,numberformatexception
I am writing an application in scala. I am trying to connect to mysql database. To do that I am using java.sql.DriverManager. But I am getting a NumberFormatException Here is my code. val user = "root" val password = "rootpassword" val url = "jdbc:mysql://root:[email protected]:3306/database_name"; Class.forName("com.mysql.jdbc.Driver") val connection: Connection = DriverManager.getConnection(url,...

Number Format Exception on a string when parsing it as a Double

java,numberformatexception
I'm running into a problem of reading from a text file off a web server, and parsing that string to a Double to use for subsequent things. This is a sample line from the web server I'm reading from. Sample line: "00501","+40.922326","-072.637078","HOLTSVILLE","NY","SUFFOLK","UNIQUE" -Data is separated by commas so I'm using...

Not able to convert a string to integer. Sometime getting NumberFormatException [closed]

java,string,exception,if-statement,numberformatexception
I am trying to get massage count, notification count and friend request count from a facebook account. After getting the string data from facebook i am converting it into interger by using Interger.parseInt(String) method. As per my code logic i am putting the data i am getting from facebook inside...

While - try - catch in Java

java,while-loop,try-catch,numberformatexception
I need a java program that ask a number between 0 and 2. If the user write 0, the program ends. If the user write 1, it executes one function. If the user write 2, it executes another function. I also want to handle the error "java.lang.NumberFormatException", with a message...

Elasticsearch NumberFormatException when running two consecutive java tests

java,date,elasticsearch,numberformatexception,spring-data-elasticsearch
I have two test in a class, each of them containing the following query: SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withFilter(rangeFilter("publishDate").lt(date)).build(); In one of the tests, the number of the results elasticsearchTemplate.count(searchQuery, Article.class), in the other one the returned values are verified elasticsearchTemplate.queryForPage(searchQuery,Article.class) If I run any of these two tests separately,...

Parsing a number throws: Exception in thread “main” java.lang.NumberFormatException: For input string

java,numberformatexception
I am making an object oriented program that takes an array of object type Date and writes it to a file. But I am having a problem parsing a number. I can't see where my int and String variables are being mixed up: public static Date[] createMe() throws FileNotFoundException {...

Java: How to turn Hex into int?

java,numberformatexception,parseint
I'm working with BufferedImage (in PNG) and want to replace a colour with another. I have all colours stored as strings for easy handling but... for(int x=0;x<output.getWidth();x++) for(int y=0;y<output.getHeight();y++) if(output.getRGB(x,y)==Integer.parseInt("ffff00fe",16)) output.setRGB(x,y,Integer.parseInt("ffaaaaaa",16)); the resultant integers should be negative numbers, but it throws NumberFormatException when I do output.getRGB(x,y) it returns negative numbers...

How to counter a java.lang.NumberFormatException in the following code? [closed]

java,string,integer,numberformatexception
I'm trying to find maximum XOR value. I'm converting the Strings p and q into the Integers n and m so I can check the exclusivity but I'm encountering a java.lang.NumberFormatException. How do I deal with that? import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution...

Android Java - NumberFormatException while parsing “76”

java,android,zlib,numberformatexception,parseint
I'm working on an Android app using zbar to decode QR. The structure of the QR is: "SpecificPrefix/[Number]". String d = sym.getData(); // I get the QR text from the symbol if(d.startsWith(QRUri)) { // QRUri is a string const containig the prefix int id; try { Log.d("NOT", "QR Subst \""...