NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Console problem?

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
YoMars



Joined: 16 Jun 2012
Posts: 1

PostPosted: Sat Jun 16, 2012 7:24 am    Post subject: Console problem? Reply with quote

Hello,
I am new to java, and attempted to write a very simple program below shown below:

Code:

package Chapter2;

import tio.*;

class SimpleInput {
    public static void main (String args[]) {
        int width, height, area;
        System.out.println("Type 2 integers for" +
                " the width and height of a box");
        width = Console.in.readInt();
        height = Console.in.readInt();
        area = width * height;
        System.out.print("The area is ");
        System.out.println(area);
    }
}


I get an error with the import tio.* as it doesn't find the package tio (and therefore Console.in isn't recognised), I've looked at the bufferedstreams, but I was wondering what the current problem with this is, or if it is simply outdated?

Sorry if its a bit of an obvious question, tried to do some searching but it came up blank, so any help would be appreciated Very Happy
Back to top
netero



Joined: 25 May 2009
Posts: 207
Location: Switzerland

PostPosted: Sat Jun 16, 2012 11:56 am    Post subject: Reply with quote

Hello,

I probably found what is tio here: http://users.soe.ucsc.edu/~charlie/java/tio

Unless I am making a mistake, this package is not included in Oracle's or OpenJdk java JDKs. Anyways NetBeans seems to ignore that package.

If you want to have in in your environment, I suggest you this:

(1) download the Tio package from somewhere
    - on the link above there is a dowload link, I don't know if it is the one you want

(2) create a "Tio" library
    - menu: Tools => Libraries
    - click the "New library" button (may not be visible at once, use the scrollbar)
    - add a .jar containing your Tio package.

(3) Link your new Library to your project
    - right click on your project, select "Properties"
    - select "Libraries", then "Compile tab", and "Add library"


Does all this help you?
regards
netero
Back to top
Gary Greenberg
Posted via mailing list.





PostPosted: Mon Jun 18, 2012 1:49 am    Post subject: Console problem? Reply with quote

No wonder it won't find it. I am working in Java for 15 years and I have no idea what the package tio is about.
May be you meant java.io.*? It is actually not a good practice to import whole packages when you need just one class out of it.
You can do
Console console = System.console();
if(console != null) {
width = console.readInt();
...
}

Have to warn you. If your program is not started from the command line System.console() always return null.
That include launching your code from within the IDE (Netbeans). It makes it difficult to debug.
You can use some other Java libs to overcome that difficulty. For example scala.Console class has a bunch of static methods for that.

Have fun

On 6/16/2012 12:24 AM, YoMars wrote:
Quote:
Quote:
Hello,
I am new to java, and attempted to write a very simple program below shown below:


Code:

package Chapter2;

import tio.*;

class SimpleInput {
public static void main (String args[]) {
int width, height, area;
System.out.println("Type 2 integers for" +
" the width and height of a box");
width = Console.in.readInt();
height = Console.in.readInt();
area = width * height;
System.out.print("The area is ");
System.out.println(area);
}
}




I get an error with the import tio.* as it doesn't find the package tio (and therefore Console.in isn't recognised), I've looked at the bufferedstreams, but I was wondering what the current problem with this is, or if it is simply outdated?

Sorry if its a bit of an obvious question, tried to do some searching but it came up blank, so any help would be appreciated Very Happy
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo