这句代码没有意义吗?为何提示我:Null pointer access?

whlweb 2012-02-28 07:22:37

public static void novelcatalogview() throws IOException {
ArrayList<Novel> novellist = null;
ArrayList<Novel> novellist2 = null;
String category = null;
System.out.println("----------------------------------");
System.out.println("0.返回上一级菜单");
System.out.println("1.武侠");
System.out.println("2.言情");
System.out.println("----------------------------------");
System.out.print("请选择:");
int choice = input.nextInt();
if (choice == 0) {
return;
} else if (choice == 1) {
category = "武侠";
} else if (choice == 2) {
category = "言情";
} else {
System.out.println("输入错误,请重新选择!");
novelcatalogview();
}
System.out.println("----------------" + category
+ "小说列表----------------");
System.out.println("序号" + "\t" + "名称" + "\t" + "简介");

novellist = cb.getNovelList();
for (Novel novel : novellist) {
if (novel.getCategory().equals("category")) {



novellist2.add(novel);

//为何上一句提示我 “Null pointer access: The variable novellist2 can only be null at this location”
//novellist2 写在这里只能是 null吗?这句代码没有意义?



}
for (int i=0;i<novellist2.size();i++) {
System.out.println(i+1 + "\t" + novel.getName() + "\t"
+ novel.getDescription());
}
}

System.out.println("----------------小说列表结束----------------");
System.out.println("阅读和下载请输入文件序号,上传请输入-1,返回请输入0:");
int choice2 = input.nextInt();
if (choice2 == 0) {
return;
} else if (choice2 != -1) {

}

}

}
...全文
1111 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
whlweb 2012-02-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yangjunloveyu 的回复:]
ArrayList<Novel> novellist2 = new ArrayList<Novel>();
[/Quote]
多谢多谢!
要不然我就掉坑里了 哈哈
小小X 2012-02-28
  • 打赏
  • 举报
回复
ArrayList<Novel> novellist2 = new ArrayList<Novel>();

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧