Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Dominik Huber
4,631 PointsKaraokemachine - recreating it on my own - a problem. Can you help me please?
So I decided to completely start over the java course where you make the Karaokemachine. But this time without any help because I have done it one time with the videos.
I'm doing good so far but now I have a problem and don't know what the problem is.
So I will post you a few links to my classes.
Class Song: http://pastebin.com/BwUJMdRk Class SongBook: http://pastebin.com/tWYj8PMp Class Karaoke: http://pastebin.com/KCpJ9ePr Class KaraokeMachine (with the main method): http://pastebin.com/PZqY92VV
The problem is following. When I start the program it asks the option. If i click add it asks the artist, then the title --> If I put in the title with more then 1 word it automatically ignores the rest of the code and starts again to ask for option.
If I put in 1 word at title it is working.
Don't know what's going on.I'm working with eclipse.
3 Answers
markmneimneh
14,133 PointsHi
replace this System.out.printf("Please add a Title:%n"); String title = mScanner.next();
with this System.out.printf("Please add a Title:%n"); String title = mScanner.nextLine();
If this helps, please make the post answered.
Thanks
markmneimneh
14,133 PointsHi
Take a look at this example where nextLine is used. Hope this helps
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
System.out.println("** Taking in User input **");
Scanner input = new Scanner(System.in);
System.out.println("Please enter your name : ");
String s = input.nextLine(); // getting a String value (full line)
System.out.println("Please enter your age : ");
int i = input.nextInt(); // getting an integer
// version with Fault Tolerance:
System.out.println("Please enter your salary : ");
while (!input.hasNextDouble())
{
System.out.println("Invalid input\n Type the double-type number:");
input.next();
}
double d = input.nextDouble(); // need to check the data type?
System.out.printf("\nName %s" +
"\nAge: %d" +
"\nSalary: %f\n", s, i, d);
// close the scanner
System.out.println("Closing Scanner...");
input.close();
System.out.println("Scanner Closed.");
}
}
Dominik Huber
4,631 PointsNope it's not working with scanner.nextLine(); It skips the input and asks directly after the title instead of artist. Actually it asks for both. When I enter a artist it jumps to enter a url. It's strange.
Tried to debug it but I don't get it.
It runs the first scanner statement and somehow doesn't wait for my input and asks the second scanner statement right away.
Any tipp? Here is a screenshot from debugging: http://imgur.com/a/ohDBc
Thx!
Dominik Huber
4,631 PointsDominik Huber
4,631 PointsHi I tried it and now the behavior is different. Now it asks for the title but it doesn't wait for my input and switches directly to the next line where it asks for the video url.
Any other idea? Should I use BufferedReader maybe?