Java hashmap will not allow get method to be called -


i have java program nested hashes. when call value inside inner nest, given error stating cannot call type object, when call getclass().getname(), given hashmap. here copy of traceback

exception in thread "main" java.lang.error: unresolved compilation problem:      method get(string) undefined type object      @ epitopeanalysis.parsecolumns(epitopeanalysis.java:88)     @ epitopeanalysis.<init>(epitopeanalysis.java:43)     @ jobmanager.<init>(jobmanager.java:42)     @ analyzer.main(analyzer.java:13) 

here copy of code

import java.awt.list; import java.lang.reflect.type; import java.util.arraylist; import java.util.collections; import java.util.hashmap;  import org.bson.types.basicbsonlist;  import com.google.gson.*; import com.google.gson.reflect.typetoken; import com.mongodb.basicdblist; import com.mongodb.basicdbobject;   public class epitopeanalysis {     int combinations;     int[] positions;     string locus;     arraylist<subject> subjects;      private static string[] validacids = {             "a","b","c","d","e","f","g","h","i","k","l","m",             "n","p","q","r","s","t","u","v","w","y","z"     };      @suppresswarnings("unchecked")     epitopeanalysis(basicdbobject jobobject) {         combinations = (int) jobobject.get("combinations");         locus = (string) jobobject.get("locus");          // create subject arraylist         gson gson = new gson();         type subjecttype = new typetoken<arraylist<subject>>(){}.gettype();         subjects = gson.fromjson(jobobject.get("subjects").tostring(), subjecttype);          // create array of positions         basicdblist _pos = (basicdblist) jobobject.get("positions");         positions = new int[_pos.size()];         (int = 0; < _pos.size(); i++) {             positions[i] = (int)_pos.get(i);         }          parsecolumns();     }      private void parsecolumns() {         arraylist<string> affectedalleles = new arraylist<string>();         arraylist<string> controlledalleles = new arraylist<string>();          // segregate alleles dx of subjects         for(int = 0; < subjects.size(); i++) {             if (subjects.get(i).dx.touppercase().equals("affected")) {                 affectedalleles.add(subjects.get(i).alleles[0]);                 affectedalleles.add(subjects.get(i).alleles[1]);             }             else if (subjects.get(i).dx.touppercase().equals("control")) {                 controlledalleles.add(subjects.get(i).alleles[0]);                 controlledalleles.add(subjects.get(i).alleles[1]);             }         }          //system.out.println(affectedalleles[4]);         /*           * generate schema analysishash          *  {          *      "affected": {          *          1: {"a": 0, "b": 0, ...},          *          2: {},          *      }          *      "control": { ... }          *  }          * */          hashmap<string, hashmap> analysishash = new hashmap<string, hashmap>();         analysishash.put("affected", new hashmap<integer, hashmap>());         analysishash.put("control", new hashmap<integer, hashmap>());         for(int = 0; < positions.length; i++) {             analysishash.get("affected").put(                         positions[i],                          generateacidhash()                     );             analysishash.get("control").put(                         positions[i],                          generateacidhash()                     );         }          /*          *  iterate on positions          *      iterate on alleles          *      append analysishash          * */             // returns java.util.hashmap             system.out.println(                 analysishash.get("affected").get(9).getclass().getname()             );              // given error here         system.out.println(analysishash.get("affected").get(9).get("a"));      private hashmap<string, integer> generateacidhash() {         hashmap<string, integer> acidhash = new hashmap<string, integer>();          for(string acid: validacids) {             acidhash.put(acid, 0);         }          return acidhash;     } } 

you've declared

 hashmap<string, hashmap> analysishash; 

where inner hashmap doesn't have type arguments. defaults object.

you're calling get(string) on object of type object.

system.out.println(analysishash.get("affected").get(9).get("a"));                                                   |     |                                                   |     |---------->is called on instance of type object                                                   | ---------------> returns instance of type object 

object doesn't have get(string) method.

change declaration to

hashmap<string, hashmap<integer, hashmap<string, sometype>>> analysishash; 

or whatever else need.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -