package com.secretary.bean;
import java.util.List;
public class SCNoteContent {
private String tid;
private String uid;
private String title;
private String content;
private String imagePath;
private String imageCount;
private String createTime;
private String updateTime;
private List<SCNoteContent> noteList;
public List<SCNoteContent> getNoteList() {
return noteList;
}
public void setNoteList(List<SCNoteContent> noteList) {
this.noteList = noteList;
}
public String getTid() {
return tid;
}
public void setTid(String tid) {
this.tid = tid;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getImagePath() {
return imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
public String getImageCount() {
return imageCount;
}
public void setImageCount(String imageCount) {
this.imageCount = imageCount;
}
}
这是一个bean
*****************************************************************************************************************
noteList 是一个存放多组bean内容的list集合
SCNoteContent note=null;
for(int j=0;j<noteList.size();j++){
note=noteList.get(j);
}
为什么这段代码将noteList.get(j);付给note时候报错java.lang.NullPointerException
import java.util.List;
public class SCNoteContent {
private String tid;
private String uid;
private String title;
private String content;
private String imagePath;
private String imageCount;
private String createTime;
private String updateTime;
private List<SCNoteContent> noteList;
public List<SCNoteContent> getNoteList() {
return noteList;
}
public void setNoteList(List<SCNoteContent> noteList) {
this.noteList = noteList;
}
public String getTid() {
return tid;
}
public void setTid(String tid) {
this.tid = tid;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getImagePath() {
return imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
public String getImageCount() {
return imageCount;
}
public void setImageCount(String imageCount) {
this.imageCount = imageCount;
}
}
这是一个bean
*****************************************************************************************************************
noteList 是一个存放多组bean内容的list集合
SCNoteContent note=null;
for(int j=0;j<noteList.size();j++){
note=noteList.get(j);
}
为什么这段代码将noteList.get(j);付给note时候报错java.lang.NullPointerException
解决方案
1
你这段代码本人没发现你这个noteList变量是怎么获取的。
1
请实例化他。
8
应该是传来的noteList是null,遍历前价格判断防止空指针吧
if(null != noteList && !noteList.isEmpty()){
for(int j=0;j<noteList.size();j++){
note=noteList.get(j);
}
}
if(null != noteList && !noteList.isEmpty()){
for(int j=0;j<noteList.size();j++){
note=noteList.get(j);
}
}
3
noteList 你断点看这个list能否为空了么
3
noteList.get(j) 假如是这里报空指针的话,那notelist.size() 就早报空指针了,请明确错误是哪里报出来的在进行修改,增加判断noteList 能否为空
1
确定是赋值那行报空么?
1
你的list里面确定放了值没?
2
应该是noteList传过来就是空的,noteList.size()这里就已经报错了。看5楼加的条件,就可以了