if ((mRawFoodN != null) && (Integer.parseInt(mRawFoodN.getTotal()) > 0)) {
totalFoods = Integer.parseInt(mRawFoodN.getTotal());
dataArray = new ArrayList<ListFoodItem>();
for (Food food : mRawFoodN.getNutrientFoodList()) {
System.out.println("food "+food+"   Constants.SMALL_IMAGE_URL  "+Constants.SMALL_IMAGE_URL);
temp = new ListFoodItem(food.getId(), Constants.SMALL_IMAGE_URL.concat(food.getImage()),
food.getName(), food.getDesc());
dataArray.add(temp);
} 错误出现在这  temp = new ListFoodItem(food.getId(), Constants.SMALL_IMAGE_URL.concat(food.getImage()),
food.getName(), food.getDesc());经测试  food非空   Constants.SMALL_IMAGE_URL为常量  难道还有可能为空的变量吗?

解决方案 »

  1.   

    测出来food.getImage()为空   请问  常量.concat(null)会出现在空指针吗?
      

  2.   

    搞定   concat方法 参数为空 会出现空指针   大家记得哦
      

  3.   

    public String concat(String str) {
    int otherLen = str.length();
    if (otherLen == 0) {
        return this;
    }
    char buf[] = new char[count + otherLen];
    getChars(0, count, buf, 0);
    str.getChars(0, otherLen, buf, count);
    return new String(0, count + otherLen, buf);
    }
    看看String concat源码就明白了。
      

  4.   

    楼主, 这个可以通过logcat 打印出的异常日志应该可以看出引起空指针的出处:String::concat