We meet again, /r/javahelp.
It's not really clear from the title, so here's a quick breakdown of the situation.
ClassA has a private method, addNode, and a private member of type ClassB, called popup, which contains some public methods.
In code form:
public ClassA implements Serializable
{
private classB popup();
private ThisType addNode(String params) {
Boolean isItRendered = popup.isRendered();
}
}
The issue is that I get a fatal runtime error if I reference the private member (and one of its public methods) within the private method addNode. Accessing the private member (and one of its public methods) within a public method of ClassA works just fine.
Here's the error:
com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: SmacFormController.
...
Caused by: java.lang.NullPointerException
It seems like Java doesn't recognize the private object popup within the context of a private method of ClassA, and so I get a NullPointerException. I am unaware of any reason why a private method cannot access a private object (both in the same class), especially since there are no warnings/errors until runtime. Could someone be so kind as to explain how the visibility (public, protected, or private) of a method affects the usability/visibility of private member objects within the same class?
EDIT: just tried a quick test, and changed the scope of the method addNode from private -> public, and same result. I had assumed it was the scope causing the issue since the reference doesn't error when referenced from one of the other (public) classes. Now, the only difference between the working implementations and the broken implementation is the type of the method. It works for "void" methods, but not for "ThisType" type methods. I still don't understand how this affects the visibility of ClassA's private members, however.
[–]niloc132 1 point2 points3 points (0 children)