File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java execution problem

 
Timothy Leong
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all, I have the following code

import java.util.Scanner;

public class ex2 {

public static void main( String args[] ) {
String name;
try
{
Scanner input = new Scanner(System.in);
System.out.println( "Please enter ur name" );
name = input.next() ;
System.out.println( "Your name is " + name);
}
catch(Exception e)
{
System.out.println("Error data type");
}
}
}


I tried compile and run on Ms Dos & eMacs. I faced problem executing the program using eMacs. It always prompt "Error data type" whereas I have no problem using MsDos at all.

I checked my Java version on both Ms Dos and emacs which turns out both are the same. I am wondering how come the coding is nothing wrong, it provides diff result on emacs?

btw, I'm using emacs installed on Win Xp. Thanks a lot
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put e.printStackTrace(); inside your catch block so we can see what the exception is. Post the complete output here (between tags please).
 
Timothy Leong
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, the errors are

java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at ex2.main(ex2.java:11)
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That exception happens when thre are no tokens to be read by the scanner. So it looks as if emacs is returning an end of input (or end of file) immediately.
But why? I do not know. Are you using Xemacs for windows?
 
Timothy Leong
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Barry Gaunt , thanks for ur reply

Yes, I am using emacs for window. I felt puzzled y I couldn't get it working using emacs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic