Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: get console to work

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default get console to work

    Hi, in the eclipse console i get the output from line 11 saying "No console".
    My question is, what can i do to get the console to work?

    import java.io.Console;
    import java.util.Arrays;
    import java.io.IOException;
     
    public class Password {
     
        public static void main (String args[]) throws IOException {
     
            Console c = System.console();
            if (c == null) {
                System.err.println("No console.");
                System.exit(1);
            }
     
            String login = c.readLine("Enter your login: ");
            char [] oldPassword = c.readPassword("Enter your old password: ");
     
            if (verify(login, oldPassword)) {
                boolean noMatch;
                do {
                    char [] newPassword1 =
                        c.readPassword("Enter your new password: ");
                    char [] newPassword2 =
                        c.readPassword("Enter new password again: ");
                    noMatch = ! Arrays.equals(newPassword1, newPassword2);
                    if (noMatch) {
                        c.format("Passwords don't match. Try again.%n");
                    } else {
                        change(login, newPassword1);
                        c.format("Password for %s changed.%n", login);
                    }
                    Arrays.fill(newPassword1, ' ');
                    Arrays.fill(newPassword2, ' ');
                } while (noMatch);
            }
     
            Arrays.fill(oldPassword, ' ');
     
        }
     
        //Dummy change method.
        static boolean verify(String login, char[] password) {
            // this method always returns true in this example.
            // modify this method to verify password according to your rules.
            return true;
        }
     
        //Dummy change method.
        static void change(String login, char[] password) {
            // modify this method to change password according to your rules.
        }
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: get console to work

    Typically this is done by using a Scanner that wraps the System.in InputStream.

    Scanner in = new Scanner(System.in);
    System.out.println("Please enter something:");
    String something = in.nextLine();

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get console to work

    Ok scanner is nice, althought i'm still intrested to get the console to work.
    Also the code above (in my first post) is no what i needed, i need it for something else, but since i had a console problem i looked for other console examples and i just posted one of them that wasn't working here.

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: get console to work

    There's a nice process to use a remote debugger described at Stack-Overflow: java.io.Console support in Eclipse IDE - Stack Overflow

    If you just want to run the program and not debug it, use the command-line to start the java program and you'll get access to the console.

    In future updates of Eclipse this may be changed so it would be more convenient (it's being discussed here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=122429).

Similar Threads

  1. A simple BOX in Console! Please Help!
    By rainexel in forum Java Theory & Questions
    Replies: 9
    Last Post: September 26th, 2011, 11:37 AM
  2. From Console to GUI : problem !!
    By hexwind in forum AWT / Java Swing
    Replies: 33
    Last Post: August 20th, 2011, 10:50 PM
  3. Console box with scanner?
    By Hallowed in forum Java Theory & Questions
    Replies: 1
    Last Post: May 26th, 2011, 12:50 AM
  4. How do i run this Accounting console app?
    By mirzahat in forum AWT / Java Swing
    Replies: 2
    Last Post: November 16th, 2010, 12:22 AM
  5. Console Application - How to run it?
    By mirzahat in forum AWT / Java Swing
    Replies: 3
    Last Post: November 16th, 2010, 12:21 AM