I have several classes (lock and key). I am trying to branch on the
outcome of boolean value of isOpen. But I keep on getting null exception
error when I try to conditional test the isOpen status. What is wrong;
Any information is greatly appreciated!
a newbee!
---------------------------------------
public class lock{
public Lock (int combination){
...
}
public boolean isOpen() {
return open:
}
public boolean open;
}
------------------------------------------
public class key{
public Key (int combination){
....
}
public void getIfOpen(){
if (lock.isOpen(true))
....
}
}
----------------------------------------------
Doug Turner - 12 Apr 2004 01:28 GMT
Your problem seems to be that isOpen is not defined as a static
(class) metnod in the lock class. You are not providing the
definition of lock in your code snippet, so I can't see how that is
initialized, but I suspect that it is not initialized at all.
Also, you have the class name as "lock" (lower case l) but the
constructor is "Lock" (upper case L). This may be a typo on your
part, but if that is the way the code is, fix it!
I none of the above makes sense, post more code or RTFM.
>I have several classes (lock and key). I am trying to branch on the
>outcome of boolean value of isOpen. But I keep on getting null exception
[quoted text clipped - 30 lines]
>}
>----------------------------------------------
Roedy Green - 12 Apr 2004 05:49 GMT
> public boolean isOpen() {
> return open:
> }
You are not showing your code. It is probably something like this:
if ( x.isOpen() )
{
...
}
Your most likely problem is that x is null.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.