getStringArray上的NPE

时间:2015-11-10 11:53:28

标签: android arrays arraylist

我在获取一系列颜色方面遇到了问题 当我从文件strings.xml中获取数据时,我收到NullPointerException Logcat在这一行报告了一个NPE:

colorList.add(Color.parseColor(colore));

的strings.xml

 <array name="colors">
 <item>#FFFFFF</item>
    <item >#FFFFF0</item>
    <item >#FFFFE0</item>
    <item >#FFFF00</item>
 </array>

适配器

public class ColorPickerAdapter extends BaseAdapter {
private Context context;
private List<Integer> colorList = new ArrayList<Integer>();
public ColorPickerAdapter(Context context) {
    this.context = context;

String colors[] = context.getResources().getStringArray(R.array.colors);
colorList = new ArrayList<Integer>();

    // add the color array to the list
        for(String colore : colors){
                colorList.add(Color.parseColor(colore));
        }
}

1 个答案:

答案 0 :(得分:1)

SELECT a.step start
     , MIN(c.step) end 
     , a.user
  FROM my_table a
  LEFT 
  JOIN my_table b 
    ON b.user = a.user 
   AND b.step= a.step - 1
  LEFT 
  JOIN my_table c 
    ON c.user = a.user 
   AND c.step >= a.step
  LEFT 
  JOIN my_table d 
    ON d.user = c.user
   AND d.step = c.step + 1
 WHERE b.user IS NULL 
   AND c.user IS NOT NULL
   AND d.user IS NULL
 GROUP 
    BY a.step, a.user;

使用<string-array name="colors"> <item>#FFFFFF</item> <item>#FFFFF0</item> <item>#FFFFE0</item> <item>#FFFF00</item> </string-array> 代替数组