Android:尝试调用虚方法' Bundle.putStringArrayList(java.lang.String,java.util.ArrayList)'在null对象引用上

时间:2016-01-10 11:28:02

标签: java android

我在下面的代码中哪里出错了?

public Bundle[] getBundle(Cursor c){
    Bundle bundle[]=new Bundle[c.getCount()];
    int i=0;
    while(c.moveToNext()){
        ArrayList<String> list=new ArrayList<String>();
        list.add(c.getString(1));
        list.add(c.getString(2));
        bundle[i].putStringArrayList("" + i, list); //Line where NullPointerException occurs
        i++;
    }
    return bundle;
}

导致logcat错误

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Bundle.putStringArrayList(java.lang.String, java.util.ArrayList)' on a null object reference

0 个答案:

没有答案