File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

My code isn't running on sites like codechef and oneide

 
Rahul Son
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code is running correctly on my NetBeans6.5 IDE.But when I submitted it on CodeChef and OneIDE if gave runtime error
My Code is:

The error comes at the user input line for v.For BufferedReader its .........

Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:417)
at java.lang.Integer.parseInt(Integer.java:499)
at a.main(Main.java:31)

And with using Scanner for user input.......

my code using Scanner as well...



the error msg is..........

Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at A01.main(Main.java:27)

Anyone please tell why is happening and how can I remove these errors which are not being shown on my IDE,infact both these codes are working well on my IDE but not on these sites compilers.Last night iI had to withdrew from an online competition because of this problem.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For starters, never do this:

You simply MUST handle exceptions, especially I/O exceptions. At least print an error message someplace where you will see it.

It's hard to tell what the program will do without knowing the input you gave. I would guess that whatever string you ran through "parseInt" wasn't in fact an integer - it may have been empty or null.

In the future, please UseCodeTags. See how much easier to read the code is now?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic