aspose file tools*
The moose likes Java in General and the fly likes please correct the code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "please correct the code" Watch "please correct the code" New topic
Author

please correct the code

akash shrimali
Ranch Hand

Joined: Jul 28, 2010
Posts: 45

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

Correct what? What should it do? What does it do instead? What doesn't it do what it should do? TellTheDetails!


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

I'd change it to this

unless there is some specific problem you are trying to solve.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jul 28, 2010
Posts: 45
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

Joined: Mar 17, 2010
Posts: 1051

have a look at here how to do it..
is simple


try to implement above line in between your code


SCJP6.0,My blog Ranchers from Delhi
akash shrimali
Ranch Hand

Joined: Jul 28, 2010
Posts: 45
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

Joined: Oct 25, 2008
Posts: 2700

System.console() can return null is no console is available. For instance in the netbeans console.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

could you please show us your new code
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

check out this code.it may contain errors because i have not run it,
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

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

Joined: Jul 28, 2010
Posts: 45
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

Joined: Oct 13, 2005
Posts: 36514
    
  16
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

Joined: Aug 15, 2010
Posts: 230
    
    2

akash shrimali wrote:
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Have you tried the sample listed in the Console API ?? (it works...)

http://download.oracle.com/javase/6/docs/api/java/io/Console.html


Regards, Rene Larsen
Dropbox Invite
akash shrimali
Ranch Hand

Joined: Jul 28, 2010
Posts: 45
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

Joined: Oct 25, 2008
Posts: 2700

Shanky Sohar wrote:
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

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

Joined: Jul 28, 2010
Posts: 45
Wouter Oet wrote:
Shanky Sohar wrote:

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

Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

With the sample in the Console API you'll come up with this code:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please correct the code
 
Similar Threads
Overhead IO : The cryptic case of the extra bytes
operator cannot be applied to ints.
Problem With Algorithm Involving Recursion and String Manipulation
[newbie] Null pointer exception ??
read next byte