0

I have the following code, with which I am trying to create a seperated list by using this class.

I have this:

public Map<String, ?> createItem(String title, String caption, String uri) {
        Map<String, String> item = new HashMap<String, String>();
        item.put(ITEM_TITLE, title);
        item.put(ITEM_CAPTION, caption);
        item.put(ITEM_URI, uri );
        return item;
    }

public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        /** @todo Draw the splash screen */
        setContentView(R.layout.list_complex);
        List<Map<String,?>> security = new LinkedList<Map<String,?>>();
        security.add(createItem("Remember passwords", "Save usernames and passwords for Web sites","uri"));
        security.add(createItem("Clear passwords", "Save usernames and passwords for Web sites","uri2"));
        security.add(createItem("Show security warnings", "Show warning if there is a problem with a site's security","uri3"));

SeparatedListAdapter adapter = new SeparatedListAdapter(this);
        adapter.addSection("Security", new SimpleAdapter(this, security, R.layout.list_complex,
            new String[] { ITEM_TITLE, ITEM_CAPTION}, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));

        ListView list = new ListView(this);

        list.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View view,
                      int position, long id) {
                 try{
                      Log.v(TAG, "Pressed id: "+(parent.getItemAtPosition(position).getClass()));
                 }catch(Exception e){
                     Log.v(TAG, "Field not found: "+e.getCause()+" : "+e.getMessage());
                 }
//Log.v(TAG, "Pressed id: "+parent.);
                  //  Intent newActivity = new Intent(view.getContext(),agones.class);     
                        //     startActivity(newActivity);

                  }
                });
        list.setAdapter(adapter);
        this.setContentView(list);

What I'm trying to do here is to get the field uri from the HashMap. If I log this out, it tells me that the class is of the instance HashMap, but when I try to use the method .get() on it, Eclipse says this:

The method get() is undefined for the type Class<capture#5-of ? extends Object>

How do I go about fixing this? I'm sorry if this is simple, but since I'm new, I cant wrap my head around this.

Janis Peisenieks
  • 4,938
  • 10
  • 55
  • 85

3 Answers3

0

Why does your createItem method return a Map<String, ?> instead of a Map<String, String>? Change it to return Map<String, String>.

You'll probably also want to change this:

List<Map<String,?>> security = new LinkedList<Map<String,?>>();

into this:

List<Map<String, String>> security = new LinkedList<Map<String, String>>();
Jesper
  • 202,709
  • 46
  • 318
  • 350
0

This has to do with Capture Conversion.

On your createItem method, you're returning a HashMap<String, String> and expect Java to bind it to Map<String, ?>.

This results in the JVM unbounding your String to an unknown type ?. thus, when you do Map<String, ?>.get(), it doesn't know how to bind an unknown type ? to a type T.

My suggestion is to return a Map<String, String> on createItem(), and

List<Map<String,?>> security = new LinkedList<Map<String,?>>();

into

List<Map<String, String>> security = new LinkedList<Map<String, String>>();
Community
  • 1
  • 1
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
0

Instead of storing your data into a HashMap create a class holding this data, and then store it into a IList or Map.

Something like this:

public class Storage
{
  public Storage(String t, String c, String u)
  {
    title = t;
    caption = c;
    uri = u;
  }

  public String title;
  public String caption;
  public String uri;
}
Drejc
  • 14,196
  • 16
  • 71
  • 106
  • Thanks, this would be great, but I was using a ready-made class, therefore this wasn't an option. But this would be the most clear for me. – Janis Peisenieks Jan 23 '12 at 10:15