• Post Reply Bookmark Topic Watch Topic
  • New Topic

QChallenge Trivia game with CSV file  RSS feed

 
Brett Banich
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempting to make a two player trivia game in java. I am reading the questions from a CSV file. I have a player class and question class as well. I don't really know what I'm doing wrong or how to fix it. Sorry for posting so much but I am lost and this project is due tomorrow night. According to eclipse I have a few errors but I am lost. This is what eclipse says: Exception in thread "main" java.lang.NumberFormatException: For input string: "A program is a sequence of instructions stored in:,The CPU,#The computer's memory,Software,Firmware,"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at QChallenge.initQuestions(QChallenge.java:70)
at QChallenge.main(QChallenge.java:30)






 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the error message the problem is one line 70 which has this
And you are giving it this data
This data IS NOT an int, therefore the parseInt() method throws this exception.
 
Brett Banich
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would I change that to? The class I am in, the instructor does not really teach java well and does not answer questions. The teacher just reads from a power point presentation.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guessing by the format of this String you have a comma delimited string where the first item is the question and subsequent items are the possible answers, and the possible answer starting with a '#' is the correct answer. So, no ints.

To break apart the string use the String#split() method. To see if a question starts with a '#' you can use String#startsWith("#"), to strip off the '#' from the correct answer you'll need to use String#substring().
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Up to line 62 you've got things correctly. On line 64 you are setting the question using the entire line, you only want the portion of the line up to the first comma. I suggest you read about the String#split method and see if you can work out how to fix that. After that we'll work on the remaining issues.
 
Brett Banich
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will reply back to this post when I change that line of code. Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!