Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please correct the code

 
akash shrimali
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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!
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd change it to this

unless there is some specific problem you are trying to solve.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • 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
  • 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




 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
check out this code.it may contain errors because i have not run it,
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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)


 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • 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 ==
 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akash shrimali wrote:
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shanky Sohar wrote:
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the sample in the Console API you'll come up with this code:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic