I am working on a project for school. The project is a game where the user needs to guess the price of an object. The price is generated randomly. The user has 5 chances to guess it. if he doesnt, th game is over and is asked if he wants to replay or not. The name of this game could be known as The Price is Right. My problem is that when i run the project it crashes just before taking the answer of the user, to know if he wants to replay.
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:658)
at pkgthepriceisrightv1.ThePriceisRightV1.main(ThePriceisRightV1.java:102)
Java Result: 1
BUILD SUCCESSFUL (total time: 7 seconds)
This is the error. I dont know what is the problem....
And here is the code lines where i am taking the information, the yes or no from the user, wich is the line 102, in the error code, i have declared all my variables. valeur_recommencer is a char, and recommencer is a string. All my code is in Java. Excuse me for the language of the code, its all in french, a requirement for school.
recommencer = lire.nextLine();
valeur_recommencer = recommencer.charAt(0);