62,615
社区成员
发帖
与我相关
我的任务
分享
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) {
}
}
}