Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  No console object in Eclipse?  (Read 4959 times)
0 Members and 1 Guest are viewing this topic.
the_jogler
Guest
« Posted 2007-09-05 03:03:50 »

Whenever I try to run my program that tries to get the current console object, it throws an IOException. Is there some way I can read input from the Eclipse console? Here's my code, if it helps.

1  
2  
3  
4  
5  
6  
public static void main(String[] arguments) throws IOException {
       Console c = System.console();
       if (c == null) {
           System.err.println("No console.");
           System.exit(1);
       }


Thanks.
Offline Jackal von ÖRF

Junior Member





« Reply #1 - Posted 2007-09-05 08:57:51 »

System.console() does not throw an IOException, so I don't think that is your problem. Read from the strack trace where the exception is thrown and what is its message.

You can also use System.in to read input.

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #2 - Posted 2007-09-05 10:25:22 »

Have you got the "allocate console" checkbox enabled in the run configuration? (Under the "common" tab).

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline JAW

Senior Member


Medals: 2



« Reply #3 - Posted 2007-09-14 10:17:01 »

I've read that console() is a Java 6 thingie and maybe your version of eclipse is not up to it. Either you need the newest Eclipse or Eclipse is not yet up to date with all stuff.

Happens from time to time with a new Java version. With Java 5 Eclipse could not handle generics in the beginning.

-JAW
the_jogler
Guest
« Reply #4 - Posted 2007-09-19 05:29:20 »

Yes, I have the "allocate console" box checked in the run configuration, and my Eclipse has the latest version of Java.  Huh
Offline Herko_ter_Horst

Senior Newbie




Java games rock!


« Reply #5 - Posted 2007-09-21 15:09:42 »

Post the full stack trace.
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #6 - Posted 2007-09-22 04:33:56 »

Do it the old fashioned way.

1  
2  
3  
4  
5  
6  
7  
8  
9  
InputStream in = System.in;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
int data;
do {
  data = in.read();
  bout.write(data);
} while(data != 13);

String input = bout.toString();

Offline broumbroum

Junior Member





« Reply #7 - Posted 2007-09-22 22:18:13 »

I'd strongly suggest to Buffer the input, as described in the doc (look at the Process.getErrorStream()). That is :
1  
InputStream in = new BufferedInputStream(System.in);
Wink

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #8 - Posted 2007-09-24 16:37:15 »

I'd strongly suggest to Buffer the input, as described in the doc (look at the Process.getErrorStream()). That is :
1  
InputStream in = new BufferedInputStream(System.in);
Wink

Whoops.  Yes.  Embarrassed

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (39 views)
2014-07-18 06:55:21

Zero Volt (36 views)
2014-07-17 23:47:54

danieldean (29 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47

Riven (37 views)
2014-07-14 11:51:35

quew8 (33 views)
2014-07-13 13:57:52

SHC (70 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!