2012-02-21 5 views
0

私はこの作業を行っていましたが、どこかで変更を加えましたが、今はエラーを追跡できません。android parse xml - Nodelistのオブジェクトが多すぎます

ここでは... _regionListを作成すると、使用している領域のxmlファイルに13の領域がありますが、_regionlist/children /配列には18個のオブジェクトがあります。別の領域(50要素)を使用して、60個のオブジェクトを作成します。

アレイ内の残りのオブジェクトには、もちろんヌルIDが付いていますが、これは問題です。どのように追加のオブジェクトがそこにスローされているかに関する考え?

おかげ

// XMLファイルを解析し

public void Parse(InputStream inStream, String inRegion) 
{ 
    try { 
     String _region = inRegion; 

     this.cFactory = DocumentBuilderFactory.newInstance(); 
     this.cBuilder = this.cFactory.newDocumentBuilder(); 
     this.cBuilder.isValidating(); 

     Document _document = this.cBuilder.parse(inStream, null); 

     _document.getDocumentElement().normalize(); 

     NodeList _regionList = _document.getElementsByTagName(_region); 
     final int _length = _regionList.getLength(); 

     for (int i = 0; i < _length; i++) { 
      final NamedNodeMap _attr = _regionList.item(i).getAttributes(); 
      final String _regionName = GetNodeValue(_attr, "name"); 

      // Construct a Region object 
      PropertiesRegion _regionObject = new PropertiesRegion(_regionName); 

      // Add to list 
      this.cList.add(_regionObject); 

      Log.d(TAG, _regionObject.toString()); 
     } 
    } 

    catch (SAXException e) 
    { 
     e.printStackTrace(); 
    } 

    catch (IOException e) 
    { 
     e.printStackTrace(); 
    } 

    catch (ParserConfigurationException e) 
    { 
     e.printStackTrace(); 
    } 
} 
+0

_document、_regionListおよびcListはすべて、追加の配列要素で初期化されます。 TrimToSizeは適切なソリューションのようですが、それは有効なオプションではありません。余計な配列インデックスを削除する必要がある他のオプションを確認できません。アイデア? – user1222760

答えて

0

ArrayList(コレクション)のnullインデックスを追加すると問題ありません。 TextViewに問題があり、それをArrayListに配線します。

0
ノードリストで

他の要素はなど、おそらく
なので、先に進む前に、ノードタイプをチェックし、あなたがあなたの問題を解決するのに役立つことがあります。

Node node=_regionList.item(i); 
if(node.getNodeType()!=3) 
{ 
     final NamedNodeMap _attr = node.getAttributes(); 
     final String _regionName = GetNodeValue(_attr, "name"); 

     // Construct a Region object 
     PropertiesRegion _regionObject = new PropertiesRegion(_regionName); 

     // Add to list 
     this.cList.add(_regionObject); 

     Log.d(TAG, _regionObject.toString()); 

} 
関連する問題