• Post Reply Bookmark Topic Watch Topic
  • New Topic

NumberFormatException Exception Error, What is it and why is it happening ?  RSS feed

 
Daniel Vargas
Greenhorn
Posts: 17
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so i'm following a guide on how to create a genetic algorithm.

I made this class that Is supposed to Generate the chromes or Possible solutions of the program. Im pretty sure It doesn't have any syntax error and I went over the logic a couple time yet Im getting a NumberFormatException Exception Error. I have no idea what this error means nor why am I getting it. I looked it up on the Oracle website and I kind of understood it a little but it still doesn't explain the whole concept of it, nor how to fix it.

Here's my code:



Here is the class with the main method


And this is the output when I run the program




Help please???
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those look like base 2 numbers (binary numbers.) If so, you have to inform Java of this when parsing. For example:

 
Daniel Vargas
Greenhorn
Posts: 17
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you explain a bit more?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Base 2 numbers just use 0s and 1's. For example, 111 is the number 7 (1+2+4).

In base 10 (normal numbers), we use the digits 0-9.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Jeanne means is that you can specify the base you are using for the parseInt and parseLong methods. Look in the API documentation for Long and Integer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!