0

In my code I am having following scenario..

class MyClass {
    void myMethod(String arg1, String arg2) {
         //Some stuff
    }
}

I am having an instance for the MyClass in some other class. I invoked the myMethod by using following code,

MethodUtils.invokeMethod(myClassInstance, "myMethod", managerMethodArguments)

managerMethodArguments were passed from another object which has the following code

String one = "one";
String two = null;
Object[] managerMethodArguments = {one, two};

The above code throws null pointer exception. The thing is I will not know the class type of managerMethodArguments, If I know then I can invoke by another method which has the class type. Any solutions?? How to proceed forward??

Edited:

I am using org.apache.commons.lang.reflect.MethodUtils

Jaya Ananthram
  • 3,433
  • 1
  • 22
  • 37
  • MethodUtils? post it plz – Zaw Than oo Jul 24 '14 at 11:06
  • Please restate your question, it's unclear to me. Is it the NPE which is thrown, or the fact that you don't know some class type? – stealthjong Jul 24 '14 at 11:11
  • http://stackoverflow.com/questions/160970/how-do-i-invoke-a-java-method-when-given-the-method-name-as-a-string – Zaw Than oo Jul 24 '14 at 11:13
  • @stealthjong In real time, the class type of arguments is not known. Hence I used the above approach. If any arguments is null, Then Null Pointer Exception has been thrown out. I need a solution to invoke a method having set of arguments which might have any one or more null arguments with out knowing the class type – Jaya Ananthram Jul 24 '14 at 11:20

2 Answers2

0

It might be occurring because your class and methods have no public access identifier , try to make public your class and method.

Ashwini Jindal
  • 811
  • 8
  • 15
0

This problem probably arising because Mechanism failed to find your method, it search by matching method name and parameters type, you have defined one parameter as null and it could not find data type of null.Try method to invoke your function with specify data type

Ashwini Jindal
  • 811
  • 8
  • 15