tags:

views:

39

answers:

5
Map<String,MyData>  map = new HashMap<String,MyData>();
...
static class MyData {
  String theString;
  Bitmap theBitmap;
  int theInt;
  ...
}

How can I put data in this map???

map.put("xxx", new MyData()); // Does not work

Thank you ;)

+1  A: 
Map<String,MyData>  map = new HashMap<String,MyData>();
...
class MyData {
  String theString;
  Bitmap theBitmap;
  int theInt;
  ...
}

See if this is better.

duffymo
Oh, static class....Good catch.
jjnguy
Apparently not - I prefer the answer below mine. I'm voting it up.
duffymo
+1  A: 

Sure it works:

import java.util.*;

public class Test {

    static class MyData {
        String theString;
        byte[] theBitmap;
        int theInt;
    }

    public static void main(String... args) {
        Map<String,MyData>  map = new HashMap<String,MyData>();
        map.put("xxx", new MyData());

        System.out.println(map);
    }
}

This compiles fine, and prints:

{xxx=Test$MyData@3ae48e1b}
aioobe
A: 

Yes sorry I aked the wrong question ;)

I ment how can I write dada in in ...

like for theString="aaa", theInt=22, etc....

Thanks

Denny
Please edit this additional information into your question.
jjnguy
+1  A: 

Maybe you want to do :

MyData someData = new MyData();
someData.theString = "toto";
someData.theString = 1;
map.put("xxx", someData);
someData = new MyData();
someData.theString = "tutu";
someData.theString = 2;
map.put("xxx", someData);
Guillaume
A: 

Based on your comment (er... answer?) I am going to guess that you forgot to add a constructor to the MyData class.

The constructor should be something like:

  public MyData(String str, Bitmap bmap, int val)
  {
     // assign the the instnace values and whatever else you neeed to do.
  }

However, when asking this kind of question please include the text of the error message so that we don't have to guess to give you answers. Also if you have changes to your question put them up in the question don't reply (stackoverflow isn't really used as a discussion board :-)

TofuBeer