java.util.scanner - Scanner hasNext() doesn't match correctly inside if statements -
I created the following code after creating a loop for a while. I can not tell why the loop is not set to view 17 lines and 15 lines
while (scan.hasNext ()) {selectedUserName.setText (scan.next ()). If (scan.nxtine () .toString () == "male") {male = new gerdio button ("male", true); } And if (scan nxtine () .toString () == "female") {female = new jeradio button ("female", true); } SelectedGenderText.setText (scan.nextLine ()); If (scan .nxt () .toString () == "warrior") {userClassBox.setSelectedItem (class [0]); } And if (scan.) (). ToString () == "wild") {userClassBox.setSelectedItem (class [1]); } And if (scan.) (). ToString () == "Dana") {userClassBox.setSelectedItem (class [2]); } And if (scan.) (). ToString () == "Thief") {userClassBox.setSelectedItem (class [3]); } SelectedClassText.setText (scan.nextLine ()); PointsText.setText (scan.nextLine ()); PointsSlider.setValue (Integer.parseInt (scan.nextLine ())); IntelligenceText.setText (scan.nextLine ()); IntelligenceSlider.setValue (Integer.parseInt (scan.nextLine ())); DexterityText.setText (scan.nextLine ()); DexteritySlider.setValue (Integer.parseInt (scan.nextLine ())); StrengthText.setText (scan.nextLine ()); StrengthSlider.setValue (Integer.parseInt (scan.nextLine ())); WisdomText.setText (scan.nextLine ()); WisdomSlider.setValue (Integer.parseInt (scan.nextLine ())); }
In my input file there are 15 lines to match the above code,
Warrior male male warrior warrior 0 10 10 30 30 60 60 0 / <> If there are two other lines to reference / what are the details? This is stuck on the following line when I run the program -
Exception in the formula "AWT-EventQueue-0" java.util.NoSuchElementException: No line found in java.util.Scanner.nextLine CharacterCreation $ Javax.swing.DefaultButtonModel at javax.swing.AbstractButton $ Handler.actionPerformed at javax.swing.AbstractButton.fireActionPerformed at OpenCharListener.actionPerformed (CharacterCreation.java:450) (unknown source) (unknown source). FireActionPerformed (unknown source)
The last two lines beginning with this reference -
wisdomText.setText (scan.nextLine ()); WisdomSlider.setValue (Integer.parseInt (scan.nextLine ()));
Why does the functionality of .nextLine () show up in 17 rows instead of 15?
Note that the scanner consumes data. So in this example:
if (scan.NXTin () .toString () == "male") {male = new JRDO button ("male", true); } And if (scan nxtine () .toString () == "female") {female = new jeradio button ("female", true); } In the first statement, you will consume data from the scanner, and if the conditional is false, then you will consume it after that which is followed by another- if in the statement. You can only string input = scan. NXTIN ();
and then compare with that stored string.
Comments
Post a Comment