Home Download Buy Blog Forum Support

Java - Error in Sublime Text 2 but not in IDE

Java - Error in Sublime Text 2 but not in IDE

Postby vick1211 on Tue Mar 05, 2013 9:26 pm

I'm trying to use Sublime text and I have changed my compiling settings to also display the output form the java program. However, I can not run it in Sublime Text 2, while IntelliJ displays it fine, as does DrJava and Eclipse.

My error is:

Code: Select all
>     -----------OUTPUT-----------
>     This program will calculate the average for the given number of student's marks
>     How many students are in the class?
>     Exception in thread "main" java.lang.NumberFormatException: null
>        at java.lang.Integer.parseInt(Unknown Source)
>        at java.lang.Integer.parseInt(Unknown Source)
>        at Unit4ClassAverage.main(Unit4ClassAverage.java:33)
>     [Finished in 0.8s with exit code 1]


The block of code responsible for this, I'm guessing is:

Code: Select all
    System.out.println("This program will calculate the average for the given number of student's marks");
                System.out.println("How many students are in the class?");
                strInput = br.readLine();
                intStudents = Integer.parseInt(strInput);


My JavaC.sublime-build file looks as follows:

Code: Select all
    {
       "cmd": ["runJava.bat", "$file"],
       "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
       "selector": "source.java"
    }


and my runJava.bat file looks as follows:

Code: Select all
    @ECHO OFF
    cd %~dp1
    ECHO Compiling %~nx1.......
    IF EXIST %~n1.class (
    DEL %~n1.class
    )
    javac %~nx1
    IF EXIST %~n1.class (
    ECHO -----------OUTPUT-----------
    java %~n1
    )

which is located in my "C:\Program Files (x86)\Java\jdk1.7.0_05\bin" folder.

Any help would be appreciated!
The full code can be seen http://pastebin.com/d5QDqMbJ
vick1211
 
Posts: 2
Joined: Tue Mar 05, 2013 9:24 pm

Re: Java - Error in Sublime Text 2 but not in IDE

Postby quarnster on Tue Mar 05, 2013 10:19 pm

Are you trying to read from the console input? That's not possible from within ST2, you'll have to run your program in a proper terminal.
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: Java - Error in Sublime Text 2 but not in IDE

Postby vick1211 on Wed Mar 06, 2013 12:32 am

quarnster wrote:Are you trying to read from the console input? That's not possible from within ST2, you'll have to run your program in a proper terminal.

Any way to launch that from within ST2? It makes things easier.
vick1211
 
Posts: 2
Joined: Tue Mar 05, 2013 9:24 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 34 guests