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

Java

I can't execute readLine nor nextLine. java.util.Scanner.nextLine(Unknown Source)

I use sublimetext 3. And I got this error. How can I fix this?

What is your name: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at Introductions.main(Introductions.java:9)

import java.util.Scanner;

public class Introductions {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // Welcome to the Introductions program!  Your code goes below here
        System.out.print("What is your name: ");
        String firstName = scan.nextLine();
        System.out.printf("Hello, my name is %s\n",firstName);
        System.out.printf("%s is learning to write Java\n",firstName);
  }
}

2 Answers

You code is correct and should work as is. I compiled it from a command line in Linux and ran it successfully, even if I didn't enter any name and just hit return. As Jon suggested, likely something wonky with your development environment.

Hi rtholen,

As you done, I should have compiled it from another environment. I'll check on Linux next time! Thank you so much!

Hi Yasuaki,

It's possible that your program isn't being run correctly. I suggest you download Eclipse instead of using Sublime Text since it is an IDE instead of a text editor. I hope that helps.

Hi Jon,

As you said, my code was correct but my environment has a problem. Sublime text doesn't accept interactive input. So I compiled it on sublime text, and launch console from sublime text and execute it. Well done! I will try Eclipse later. Thank you so much!