• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java execution problem

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic