Hi All,
I've been facing a very wierd problem.
I have two classes, A & B under the same package XYZ.
A has a method, a(); and B has a method b(), which calls a().
A is a singleton class.
What's wierd is that for some unknown reason I can't get to the current instance of A, from B's b() and get an Exception which shouldn't even be occuring (since those parts of a() aren't reached during execution)!
And when I can the same bit of code from A's main method, it works!
This is what I mean.. here's how the code looks like:
public class A
{ private static A instance;
//Returns the current instance of this class
public static A getInstance()
{ if(instance==null)
instance = new A();
return instance;
}
public void a()
{ System.out.println ("Inside a()");
//..
//Some operations..
//..then..
if(someVeryRareCondition)
throw new ExceptionA(reasonOfExceptionString)
}//end-of-a()-method
public static void Main(String[] args)
{ A.getInstance().a(); //<--This works, prints the String "Inside a()"
}
}//end-of-class A
public class B
{ public b()
{ A.getInstance().a(); //<--This does NOT work, get the ExceptionA
}
}//end-of-classB
Infact, even if b() looked like :
public b()
{ A objA = A.getInstance(); //--(pt.A)
objA .a(); //--(pt.B)
}
Before it reached (pt.A), I'm getting the above mentioned Exception..
There's no other class where such an Exception is ever thrown or caught.
[ExceptionA belongs to the same package XYZ].
Any comments would be greatly appreciated.
Thanks in advance.
Nirmalya