2014-01-14 37 views
0

我有一個從一個活動傳遞一個樹狀圖中其他

TreeMap<String, ArrayList<Video>> mShows = new TreeMap<String, ArrayList<Video>>(); 

,我試圖通過從一個活動到另一個。我曾嘗試

putExtra treeMap returns HashMap cannot be cast to TreeMap android

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Intent i = getIntent(); 
    Bundle bun = i.getBundleExtra("lascategorias"); 
    mCategories = bun.getStringArray("categories"); 
    mShows = new TreeMap<String, ArrayList<Video>>(Map<String,ArrayList<Video>> getIntent().getExtras().get("map"));   
} 

,但它說,地圖,字符串和ArrayList中解決不了的地方,我已經(圖>)

這是我如何添加它的變量

protected void onPostExecute(final String json) { 
     Log.i(LOG_TAG, "decoding..."); 
     if (json == null) 
      return; 
     try { 
      final URI base = new URI(mUrl); 
      final JSONObject jso = new JSONObject(json); 
      final JSONArray ja = jso.getJSONArray("categories"); 
      for (int i = 0; i < ja.length(); i++) { 
       final JSONObject list = ja.getJSONObject(i); 
       final ArrayList<Video> vidList = new ArrayList<Video>(10); 
       mShows.put(list.getString("name"), vidList); 
       final JSONArray videos = list.getJSONArray("videos"); 
       for (int j = 0; j < videos.length(); j++) { 
        final JSONObject vids = videos.getJSONObject(j); 
        final JSONArray sources = vids.getJSONArray("sources"); 
        try { 
         final Video v = new Video(base.resolve(vids.getString("thumb")), 
           base.resolve(sources.getString(0)), vids.getString("title"), 
           vids.getString("subtitle"), vids.getString("description")); 
         vidList.add(v); 

         // The rare case that I've got more than one 
         for (int k = 1; k < sources.length(); k++) { 
          v.mSource.add(base.resolve(sources.getString(k))); 
         } 
        } catch (IllegalArgumentException expected) { 
         Log.e(LOG_TAG, "Bad Json."); 
        } 
       } 
      } 
     } catch (final JSONException je) { 
      Log.e(LOG_TAG, "An error in the JSON." + je.getMessage()); 
     } catch (final URISyntaxException se) { 
      Log.e(LOG_TAG, "URI syntax error" + se.getMessage()); 
     } 
     //onDataComplete(); 
     mCategories = getCategories(); 
     Bundle b = new Bundle(); 
     b.putStringArray("categories", mCategories); 
     //b.p 
     Intent i = new Intent("com.video.tv.MainActivity"); 
     i.putExtra("las Categorias", b); 
     i.putExtra("map", mShows); 
     startActivity(i); 
     finish(); 
    } 
} 

I declared mShows earlier 
public TreeMap<String, ArrayList<Video>> mShows = new TreeMap<String, ArrayList<Video>>(); 
+0

問題是什麼? – Melquiades

+0

我收到一個錯誤,指出Map >無法解析爲類型 – aafonso1991

+0

請發佈更多代碼(您在哪裏調用上述代碼)。另外,您的施工圖=新的TreeMap <...>(...)getIntent ...不正確。 – Melquiades

回答

0

在getIntent()之前缺少一個右括號。正確格式:

mShows = new TreeMap<String, ArrayList<Video>>((TreeMap<String, ArrayList<Video>>) getIntent().getExtras().get("map")); 
+0

感謝您的幫助。這解決了問題 – aafonso1991

+0

不客氣。 – Melquiades

+0

我認爲錯誤已解決,但我得到java.util.HashMap不能轉換爲java.util.treemap – aafonso1991

相關問題