java - How to assign value for a class array object? -


i modifying program, , has class[] paramtypes store input type. question how can assign value each cell of array? can paramtypes = new class[]{int.class,double.class,string.class} assign paramtypes, when try assign each cell in loop paramtypes[i] = int.class, shows nullpointerexception. how shoud in loop?

this method:

    public methodcall(string classname,         string methodname,         class[] paramtypes,         object[] params) {     this.classname = classname;     this.methodname = methodname;     this.paramtypes = paramtypes;     this.params = params; } 

this instance:

methodcall methodcall = new methodcall("foo", "bar", new class[]{int.class,double.class},new object[]{new integer(10), new double(123.0)}); 

you have initialize array first.

paramtypes = new class[4]; // or other number for(...){   paramtypes[i] = int.class; } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -