• 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

please correct the code

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct what? What should it do? What does it do instead? What doesn't it do what it should do? TellTheDetails!
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd change it to this

unless there is some specific problem you are trying to solve.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't get it; password is an array of nothing chars. Are you trying to do something with the input?
 
akash shrimali
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i just want that when user inputs password it must be taken in the form
password ********


and want to store those entered characters in array !!!as well how to store the user input in array of character
thats what i need to ask in the code
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have a look at here how to do it..
is simple


try to implement above line in between your code
 
akash shrimali
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its still showing


Exception in thread "main" java.lang.NullPointerException
at javaapplication5.login.login(Main.java:20)
at javaapplication5.login.main(Main.java:34)
Java Result: 1




 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.console() can return null is no console is available. For instance in the netbeans console.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could you please show us your new code
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check out this code.it may contain errors because i have not run it,
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shanky is right - System.console() is the only way to do this on the console. And Wouter is right too, the console is only available if you launched your application from a real console; IDEs don't have a real console.

Note that you will not get stars; instead nothing is printed at all.
 
akash shrimali
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Console console = System.console();

if (console != null) {
System.out.println("Console is not available");
System.exit(1);
}
System.out.println("PASSWORD \n");
char[] passw;
passw= console.readPassword("[%s]", "Password:") ;
for(int i=0;i<=passw.length;i++)
{
System.out.print("*");
if(passw[i]==13)
{
break;
}
passw[i]='\0';
}
}

}
USER NAME


akash
PASSWORD

Exception in thread "main" java.lang.NullPointerException

PASSWORD
at javaapplication5.login.login(Main.java:23)

at javaapplication5.login.main(Main.java:40)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)


 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use the code tags. You start off with a test if (console != null) . . . and crash if the console is not null. Maybe you meant to use ==
 
Ranch Hand
Posts: 258
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

akash shrimali wrote:

 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried the sample listed in the Console API ?? (it works...)

http://download.oracle.com/javase/6/docs/api/java/io/Console.html
 
akash shrimali
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raymond Tong wrote:

akash shrimali wrote:


its still giving error in netbeans as null pointer exception , please check in the code



 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shanky Sohar wrote:

 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

akash shrimali wrote:

Raymond Tong wrote:

akash shrimali wrote:


its still giving error in netbeans as null pointer exception , please check in the code




It will not work from inside netbeans - you need to run it from terminal (command prompt) where you can get the required console.
 
akash shrimali
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wouter Oet wrote:

Shanky Sohar wrote:


passw= console.readPassword() ;
this line is giving the actual problem

 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the sample in the Console API you'll come up with this code:
 
reply
    Bookmark Topic Watch Topic
  • New Topic