Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mac Player

macrumors regular
Original poster
Jan 19, 2006
225
0
Hi everyone,

i wrote this piece of code on windows using Eclipse ad it compiled and ran fine:
import java.util.Scanner;

public class AgendaTest {

public static void main(String[] args) {

Scanner in = new Scanner (System.in);

boolean done = false;

System.out.println ("Defina o tamanho da agenda:");
int tamanho = in.nextInt();

}
}

, i tried to compile and run this code on my mac, it compiled fine but i cant get it to work, the terminal shows this message:

Defina o tamanho da agenda:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:817)
at java.util.Scanner.next(Scanner.java:1431)
at java.util.Scanner.nextInt(Scanner.java:2040)
at java.util.Scanner.nextInt(Scanner.java:2000)
at AgendaTest.main(AgendaTest.java:12)

Program exited with status 1.

I hope someone can help.

TIA
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
It doesn't seem to be able to find anything to read in, have you typed in anything?

Also what version of Java are you using (check with java -version), Scanner requires Java 1.5 or 1.6
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
Your class seems to work fine here, both from the command line and from within Xcode. What environment are you using to edit and compile your Java stuff? How are you running it?
 

Mac Player

macrumors regular
Original poster
Jan 19, 2006
225
0
Your class seems to work fine here, both from the command line and from within Xcode. What environment are you using to edit and compile your Java stuff? How are you running it?

I was using Textmate.

The funny thing is that this code works when compiled through eclipse or XCode.
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
Oh. Are you launching the compiled .class or .jar from within textmate or something like that? Maybe it simply isn't handing standard input off to to the keyboard. Does it work okay if you instead run it from a Terminal shell prompt?
 

Mac Player

macrumors regular
Original poster
Jan 19, 2006
225
0
Oh. Are you launching the compiled .class or .jar from within textmate or something like that? Maybe it simply isn't handing standard input off to to the keyboard. Does it work okay if you instead run it from a Terminal shell prompt?

Its runs ok in the Terminal. So, i guess Textmate's run window doesnt allow inputs.

Thanks for all the help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.