aspose file tools*
The moose likes Beginning Java and the fly likes Java execution problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java execution problem" Watch "Java execution problem" New topic
Author

Java execution problem

Timothy Leong
Ranch Hand

Joined: May 25, 2005
Posts: 55
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

Joined: Aug 03, 2002
Posts: 7729
Put e.printStackTrace(); inside your catch block so we can see what the exception is. Post the complete output here (between tags please).


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Timothy Leong
Ranch Hand

Joined: May 25, 2005
Posts: 55
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

Joined: Aug 03, 2002
Posts: 7729
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

Joined: May 25, 2005
Posts: 55
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Java execution problem