javascite

Unable to execute Java code in SciTE


I have written a sample code:

import java.util.Scanner;

 public class abcd {
    public static void main(String[] args) {
        System.out.print("please enter a: ");
        Scanner a = new Scanner(System.in);
        String b = a.next();
        System.out.println(b);
    }
}

I am able to compile and execute this code via Ubuntu terminal. In SciTe, it compiles fine, but when I run it, I am faced with this error:

please enter a: Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Scanner.java:862)
    at java.util.Scanner.next(Scanner.java:1371)
    at abcd.main(abcd.java:8)

Any Suggestions?

EDIT: When I execute a file in terminal, I do: 'java abcd' Scite does: 'java -cp .abcd'. How are the two commands different and why isn't java -cp working?


Solution

  • It appears that there is a bug/improper implementation in the handling of standard input in SciTE on Linux/Unix.

    The description of the bug and a workaround are in this PDF document: A Problem with SciTE Go Command on Linux

    Note: this is not official documentation, but it seems to match your problem.

    According to that document, when running a Java program through the "Go" command on SciTE, input is supposed to come from the output pane. However, on Linux this does not work properly, and it's as if you are reading from an empty stream.

    When you are reading from an empty stream, Scanner sees the end-of-file marker when it attempts to read a value using next(), nextInt() etc. And it throws a NoSuchElementException as there is no input element in the stream.

    Your options to work around this problem: