java - Use custom class in HashMap in android -


edit: have posted earlier java. working in java not in android. posting android code now.

i trying use custom class hashmap in android application. not giving desired output. please help.

i want this...

//code android application:

//point class

class point{  private int x;  private int y;  public point(){  } public point(int _x, int _y){   this.x = _x;   this.y = _y; }  } 

datamanager.java

public class datamanager {      private vector<integer> rssi = null;     private int numofrssi;      private map<vector<integer>, point> singledata = null;     private vector<map<vector<integer>, point>> data = null;     private context context;      public datamanager(context _context) {         this.context = _context;                 data = new vector<map<vector<integer>, point>>();     }      public void loaddata(string filename) {         if (data == null) {             system.out.println("***error: dataset not initalized!!!\n");         }         readfile(filename);     }      public void printdata(){                 vector<integer> rssi = null;         map<vector<integer>, point> single = null;         point point = null;          for(int i=0;i<data.size();i++){         single = new hashmap<vector<integer>, point>() ;         single = data.get(0);          (map.entry<vector<integer>, point> entry :single.entryset()) {                rssi = new vector<integer>();                          point = new point();                           rssi = entry.getkey();               point = entry.getvalue();                          system.out.print("("+point.x+" "+point.y+") ");                for(int j = 0;j<rssi.size(); j++){                   system.out.print(rssi.get(j)+" ");               }                          system.out.println("");         }                }            }      private void readfile(string filename) {          inputstream = null;         try {             = context.getresources().getassets().open("datasets.txt");         } catch (ioexception e) {             e.printstacktrace();             system.out.println("error file reading");         }          if (is != null) {              stringbuilder text = new stringbuilder();             int flag = 0;              try {                 bufferedreader br = new bufferedreader(                         new inputstreamreader(is));                  string line;                  while ((line = br.readline()) != null) {                      if(flag==0){                         flag=1;                         this.numofrssi = integer.parseint(line);                         system.out.println("number of rssi: "+numofrssi);                     }                     else if(flag==1){                         parseline(line);                     }                  }              } catch (ioexception e) {                 // error reading file             }              {                 // myhelper.print(text.tostring());              }         }      }      private void parseline(string line) {          rssi = new vector<integer>();         singledata = new hashmap<vector<integer>, point>();           stringtokenizer st = new stringtokenizer(line, ",");         int co = 0;         int x=0,y=0;         while (st.hasmoretokens()) {              if(co < this.numofrssi){                 rssi.add(integer.parseint(st.nexttoken()));                 co++;             }             else{                 x = integer.parseint(st.nexttoken());                 y = integer.parseint(st.nexttoken());             }          }          point point = new point(x,y);          singledata.put(rssi, point);          data.add(singledata);     }  } 

mainactivity.java

public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);          datamanager datamanager = new datamanager(mainactivity.this);          datamanager.loaddata("datasets.txt");          datamanager.printdata();     }  } 

datasets.txt

5 -61,-51,-46,-41,-28,1,0

-60,-50,-51,-47,-34,2,0

-72,-52,-53,-55,-37,3,0

-60,-44,-58,-53,-40,3,1

-68,-55,-46,-47,-45,2,1

-66,-60,-48,-43,-37,1,1

-62,-57,-49,-45,-34,0,2

output showing.....

1 0 -61 -51 -46 -41-28

1 0 -60 -50 -51 -47 -34

1 0 -72 -52 -53 -55 -37

etc.....

but should be...

1 0 -61 -51 -46 -41-28

2 0 -60 -50 -51 -47 -34

etc...

so problem.

try changing:

single = data.get(0); 

to

single = data.get(i); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -