getDeclaredMethod in Java Fails -


i have batch app uses file input method names , names used execute method same name design.

eg file has gettemperature , gettemperature executed in class.

i using following java:

java version "1.7.0_55" openjdk runtime environment (icedtea 2.4.7) (7u55-2.4.7-1ubuntu1~0.13.10.1) openjdk 64-bit server vm (build 24.51-b03, mixed mode) 

the code is:

 if (args.length < 2) {         system.out.println("sf   <retailername> retailername <manname> man");         system.exit(1);     }     getsoogrdata wa = new getsoogrdata();     try {         bufferedreader bf = new bufferedreader(new filereader(args[0]));          string line = null;         while ((line = bf.readline()) != null) {             class c  = wa.getclass();               c.getdeclaredmethod(line, null);         } 

the compiler gives warnings raw type (class raw type) , warnings on getdeclaredmethod saying type. class declared:

public class getsoogrdata {      private hashmap<string, integer> worddictionary =   new hashmap<string, integer>();     private file inputfile;      private file outputfile;     private string retailername;     private string man;     private string[] word;      public void gettemperature() {         system.out.println("device temp");     } 

i testing gettemperature.

i have tried few versions of code , there no error no result either. code seems ignore method completely. tested without getdeclaredmethod , worked ok, method can reached , class instantiated. hence error lies actual getdeclaredmethod. saw java version can affect this.

has solution?

you should doing like:

method method = c.getdeclaredmethod(line); method.invoke(wa);//this call method whatever there in line method without parameters 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -