invoke method from outside package

Hello every body , i have the follwoing code : file a.java conatin : class a { ....... public void invokeUserMethod(){ System.out.println("i'm here ") ; m.invoke(......) ; ................. } }// a file b.java conatin : class b { void m() { ................ ; invokeUserMethod() ;............. } }//class b the previous will work correctly .However , when i put class a in package then i import it in class b and from class b i call method invokeUserMethod then the problem araise and the result be at run time : i'm here NullPoinetr.... is this mean that invoke method can't call method from outside package and is there is any solution for this problem . please i need any body to tell me where is the problem and what is the solution Thanks a lot Nada

Your method is defined as "public" so you are able to call it from outside of the package. Which you are doing successfully. If you were not able to call the method, if for example it was defined as "private", than you would get a compiler error. So there must be some other problem. When you say "NullPointer..." do you mean that your program has crashed? Can you post the stack dump?

Please ignore post, I have no idea what I am talking about.

Nada Mohammed
Ranch Hand

Joined: Sep 22, 2000
Posts: 30

posted Oct 19, 2001 15:34:00

0

Thanks for reply my method is public but i think the problem with invoke method it self . NullPointer mean that invoke can't found the method and i think this happen because class import package set in differnt sudirectry to the package BUT if i change the order of the subdirectires to solve invoke problem i will get anther problem so pleeease i need solution

Nada Mohammed
Ranch Hand

Joined: Sep 22, 2000
Posts: 30

posted Oct 19, 2001 15:38:00

0

Thanks for reply , my method is public therefore i think the problem with invoke method may be it can't invoke method from class set in different directry than the package that's why NullPointer... exception appear at run time .However, if i change the directry i will get new problem . so pleeease i need solution for this problem Nada

Your invokeUserMethod() is a Member Method. Therefore you need to call it on an instance of class a Mya.invokeUserMethod() When the JVM went to look for the instance to call the method on, there was nothing there . . . therefore a nullPointerException. Create an instance of class a and use it to call the method, OR make the method static and use the class name to invoke the method. ClassName.staticMethod();