2011-08-08 8 views
0

だから、私がしようとしているのは動的expandableListViewを作成することだけです。現在、groupViewsを実行するだけで動作します。この問題は、groupViewsの子どもたちに人を移す必要があるときに起こります。私が何か間違っているのか、それをやるのにもっと良い方法があるのか​​分かりません。誰かが知っているなら私に知らせてください。私は何でもできる。expandableListViewを動的に設定する

現在、私はサーバーからデータを引き出していますが、私が得ているエラーはJavaのNULLポインタの例外です。だから私はそれが私の配列のサイズをどれくらい大きくしたかと関係があるかもしれないと思っています?

private static String[][] children = new String[7][4]; 
private static String[] groups = new String[7]; 

ここでは、ビューにデータを挿入しようとするときの残りのコードを示します。

public void getData(){ 
    try { 
     int tempGroupCount = 0; 
     URL food_url = new URL (Constants.SERVER_DINING); 
     BufferedReader my_buffer = new BufferedReader(new InputStreamReader(food_url.openStream())); 
     temp = my_buffer.readLine(); 
     // prime read 
     while (temp != null){ 
      childrenCount = 0; 
      // check to see if readline equals Location 
      //Log.w("HERasdfsafdsafdsafE", temp); 
      // start a new location 
      if (temp.equalsIgnoreCase("Location")) 
      { 
       temp = my_buffer.readLine(); 
       groups[tempGroupCount] = temp; 
       tempGroupCount++; 
       Log.w("HERE IS TEMP", temp); 
      } 
      temp = my_buffer.readLine(); 
       while (temp.equalsIgnoreCase("Location") == false){ 
        Log.w("ONMG HEHREHRHERHER", temp); 
        children[groupCount][childrenCount] = "IAJHSDSAD"; 
        childrenCount++; 
        temp = my_buffer.readLine(); 
       } 
       groupCount++; 
     } 

     my_buffer.close(); 
    } catch (MalformedURLException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     Log.e("IO EXCEPTION", "Exception occured in MyExpandableListAdapter:" + e.toString()); 
    } 
    } 

答えて

0

あなたはeasallyリストからデータを追加したり、削除することもできますので、私は最初の(あなたがそれをグーグルことができます)例arraylist2dのためのいくつかの2Dコレクションに文字列の配列を置き換えます。 BaseExpandableListAdapterを拡張したアダプタを作成した場合は、何も問題なく処理する必要があります。 NULLPointerについて、スタックトレースを貼り付けることができますか? - 私に

+0

をそれは私に与えますwhile(temp.equalsIgnoreCase( "Location")== false)の行でこの関数を呼び出そうとするとヌルポインタ例外が発生する – cj1098

+0

他に誰かがアイデアを持っていますか? – cj1098

1

それは、ループ内のエラーのように見えるあなたがチェックを行わずに、別の行を読んでいると、それがnullである

あなたのwhileループは、このmethinksのようなものになります。

// prime read   
while (temp != null){    
    int childrenCount = 0;    
    // check to see if readline equals Location  
    // start a new location 
    //Log.w("HERasdfsafdsafdsafE", temp);    
    if (temp.equalsIgnoreCase("Location"))    
    {     
     temp = my_buffer.readLine();     
     groups[tempGroupCount] = temp;     
     tempGroupCount++;     
     Log.w("HERE IS TEMP", temp);    
    } 
    //>>remove following line as that one isn't checked and 
    //>>you are loosing on a line that is potentialy a child 
    //temp = my_buffer.readLine(); 
    //>>check do you have first item to add subitems 
    else if (tempGroupCount>0){ 
     while (temp.equalsIgnoreCase("Location") == false){      
     Log.w("ONMG HEHREHRHERHER", temp); 
     children[tempGroupCount-1][childrenCount] = "IAJHSDSAD";      
     childrenCount++;      
     temp = my_buffer.readLine();     
    } 
    //>>next counter is probably not need but can't see if you're using it somewhere else     
    //groupCount++;   
}