aspose file tools*
The moose likes Java in General and the fly likes invoke method from outside package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "invoke method from outside package " Watch "invoke method from outside package " New topic
Author

invoke method from outside package

Nada Mohammed
Ranch Hand

Joined: Sep 22, 2000
Posts: 30
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
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

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
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
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
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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();

"JavaRanch, where the deer and the Certified play" - David O'Meara
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Try recompiling both classes. The compiler should explain to you about the access restriction and thus you wont see the run time exception.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: invoke method from outside package