在android中得到错误

问题描述:

我已经使用sax解析器成功解析了数据,输出在logcat中正常运行,但我必须系统地安排这些数据。但问题是我的问题长度和索引是2,所以选项也来了2.相反,他们是4每个问题。请建议在android中得到错误

代码段是

for (int i = 0; i < categorylist.getTitle().size(); i++) { 

      TableRow tr = new TableRow(this); 
      tr.setPadding(2, 2, 2, 2); 

      TableLayout.LayoutParams tableRowParams= 
        new TableLayout.LayoutParams 
        (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.FILL_PARENT); 

      int leftMargin=0; 
      int topMargin=2; 
      int rightMargin=0; 
      int bottomMargin=1; 

      tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin); 

      tr.setLayoutParams(tableRowParams); 

      name[i]= new TextView(this); 
      name[i].setText(categorylist.getTitle().get(i)); 
      name[i].setTextColor(Color.WHITE); 
      name[i].setTextSize(12); 
      name[i].setPadding(10,0,0,0); 
      name[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 
      tr.addView(name[i]); 
      t1.addView(tr, tableRowParams); 

      LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
        RadioGroup.LayoutParams.WRAP_CONTENT, 
        RadioGroup.LayoutParams.WRAP_CONTENT); 

      rad1[i]= new RadioButton(this); 
      rad1[i].setText(categorylist.getValue().get(i));  
      rad1[i].setTextColor(Color.WHITE); 
      rad1[i].setTextSize(12); 
      rad1[i].setPadding(10,0,0,0); 
      rad1[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 
      rgrp.addView(rad1[i], 0, layoutParams); 

     } 

和XML是

<Values> 
<Question> 

<Description><![CDATA[Some Question]]></Description> 

        <Options> 

         <option value="correct"><![CDATA[All of these]]></option> 

         <option value="incorrect"><![CDATA[Ok]]></option> 

         <option value="incorrect"><![CDATA[Fine]]></option> 

         <option value="incorrect"><![CDATA[Good one]]></option> 





        </Options> 

      </Question> 

</Values> 

logcat的输出是:

05-14 15:22:27.228: INFO/This is the title:(559): Which of the following are called celestial bodies? 
05-14 15:22:27.248: INFO/This is the option:(559): All of these 
05-14 15:22:27.248: INFO/This is the option:(559): Sun 
05-14 15:22:27.248: INFO/This is the option:(559): Planets 
05-14 15:22:27.248: INFO/This is the option:(559): Moon 
05-14 15:22:27.258: INFO/This is the title:(559): In our solar system, _________ planets revolve around the Sun. 
05-14 15:22:27.258: INFO/This is the option:(559): eight 
05-14 15:22:27.258: INFO/This is the option:(559): five 
05-14 15:22:27.258: INFO/This is the option:(559): ten 
05-14 15:22:27.258: INFO/This is the option:(559): nine 
+0

请增加一个完整的logcat输出到问题 – thepoosh

+0

所以如果你知道每个问题的选项是4然后写4而不是大小问什么是 – Nitin

+0

我也试过。但它是抛出错误。数组超出限制的异常。 – Naina

我想你应该有两个环例如

int l; 
    for (int i = 0; i < categorylist.getTitle().size(); i++){ 
    for(int j= 0; j < optionlist.size()/categorylist.getTitle().size(); j++){ 
    //add option to question 
l=l++; 
//use l; 
    } 
    } 
+0

是啊现在它获得所有8个单选按钮,但重复第二个问题的第一个问题的选项 – Naina

+0

检查更新并接受答案使用更新,因为j总是从0开始 – Nitin

+1

好.. Thanx很多:) – Naina