• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

What can I do to fix this error?  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program takes a users input (zip code) and converts it into a bar code. I am getting an error when I call one of the methods and it's telling me it doesn't like something about parsing. I was running it perfectly yesterday.
Screen-Shot-2017-09-08-at-7.40.12-PM.png
[Thumbnail for Screen-Shot-2017-09-08-at-7.40.12-PM.png]
Screen-Shot-2017-09-08-at-7.40.30-PM.png
[Thumbnail for Screen-Shot-2017-09-08-at-7.40.30-PM.png]
 
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

The error tells you that at least one of the items in zipCodeArray is the empty string. Which, of course, isn't a valid integer that can be parsed into a number.
 
Richard Gonzales
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Welcome to the Ranch.

The error tells you that at least one of the items in zipCodeArray is the empty string. Which, of course, isn't a valid integer that can be parsed into a number.




I've been bumping my head over and over. I can't seem to find a solution for this. Any thoughts on how I can fix this?
 
Bear Bibeault
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the problem is with the items in zipCodeArray, begin by inspecting the items and figure out how empty strings are getting into it in the first place. Perhaps you need to rethink how that array is getting populated.
 
Richard Gonzales
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:As the problem is with the items in zipCodeArray, begin by inspecting the items and figure out how empty strings are getting into it in the first place. Perhaps you need to rethink how that array is getting populated.



Yes, it took me a while to find but I just had to start at element 1 in the for loop.
 
Bear Bibeault
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Richard Gonzales
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





this method takes in a string and assigns the string to zipCodeArray

Can someone go more in depth on this line of code      

Why is there quotations inside the parameters and what does it do?
 
Bear Bibeault
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you familiar with Javadoc? Here is the Javadoc for the String class. You can look up the description of the split() method.
 
Richard Gonzales
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Are you familiar with Javadoc? Here is the Javadoc for the String class. You can look up the description of the split() method.



Yes, thank you. I am new to the site so I don't know how things work in here yet.

Yes, I am aware of the Javadoc. I know that it will split the string whenever it sees "". But what is "" ? is it an empty character?
 
Saloon Keeper
Posts: 5161
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is an empty String, a.k.a. a zero length String.

This is one of those non-obvious uses. It splits out Strings that are 1 character in length.
"12345" --> "1", "2", "3", "4", "5"
 
Ranch Hand
Posts: 202
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why don't we trim() or use isEmpty() before trying parse the Integer.I mean to say if(somethingXXX[i] != "") then get into iterate the rest of array ?

Perhaps the scanner expecting  "" to be recognise as a character in the barcode ? we can refer FRS(Functional Requirement) and do think accordingly.
 
Mohammed Sardar.
Ranch Hand
Posts: 202
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wish to add a simple thought for any country getting "" into a zip Code does not seem to be valid character hence can be ignored before converting to barcode!!!.
 
Mohammed Sardar.
Ranch Hand
Posts: 202
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Big sorry. trim removes only leading and trailing spaces. Let us try and solve further.
 
Mohammed Sardar.
Ranch Hand
Posts: 202
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

H. Cuellar wrote:

Bear Bibeault wrote:Welcome to the Ranch.

The error tells you that at least one of the items in zipCodeArray is the empty string. Which, of course, isn't a valid integer that can be parsed into a number.




I've been bumping my head over and over. I can't seem to find a solution for this. Any thoughts on how I can fix this?



Hi Cuellar. Greetings.  Inserting just immediate for loop helps here. But Ladies and Gently men your comments are welcome.

Kindest Regards


 
Sheriff
Posts: 23877
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I've lost track of what your problem is now. Could you recap what's left after all of those posts?

By the way you started with problems with parsing, but I don't understand why you did that in the first place. If you want to know whether a one-character string is "1" there's no need to parse the string to an integer and compare the result to 1, is there?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!