2013-11-15 27 views
1

我正在從事涉及從聯機數據庫獲取用戶列表的j2me項目,然後我打算使用用戶的名稱填充列表,並且該數目可能非常大。我的問題是 - 你可以追加到列表中的項目數是否有限制?J2ME列表中項目的最大數量

HttpConnection hc = (HttpConnection); 
    String reply; 
    Connector.open("http://www.xxxxxxxxxxxx.com/......?xx=xx"); 
    InputStream is = new hc.openInputStream(); 
    int ch; 
     // Check the Content-Length first 
      long len = hc.getLength(); 
     if(len!=-1) { 
     for(int i = 0;i<len;i++) 
     if((ch = is.read())!= -1) 
      reply += (char) ch; 
     } else { 
     // if the content-length is not available 
     while ((ch = is.read()) != -1) 
      reply += (char) ch; 
     } 
    is.close(); 
    hc.close(); 
    DataParser parser = new DataParser(reply); // This is a custom class I created to process the XML data returned from the server to split it into groups and put in an array. 
    List user list = new List("Users"); 
    if (parser.moveToNext()) { 
    do { 
    list.append(parser.get(), null); 
    } 
    } 

此代碼似乎工作正常,但我的問題是,如果保持通話list.append(「」,空),會得到它的一個點時,一些異常被拋出,也許在的情況下, 50,000個名字(列表項)?

+0

你能不能分享一下你已經開始的,我的意思是實際的實現而不是概念? –

+0

這就是我可以添加的最好的,我從Android設備打字 – francis994

+0

只需測試它! for(int i = 0; i <50000; i ++){list.append(「item」+ i);}它可能有效,但可能會令人無法接受。 – Meier

回答

0

某些實現可能有限制。較早的索尼愛立信手機在列表中限制256項。無論如何,正如Meier所指出的,真正有很多項目的列表可能很慢或很難使用。而50k的字符串可能很容易導致低堆設備(1 - 2 MB)的OOM。