问题描述
importjava.util.*;publicclassdvdmgr{dvdsetdvd=newdvdset();Scannerinput=newScanner(System.in);publicvoidsetdata(){dvd.initial();}publicvoidstartmenu(){System.out.println("欢迎使用MiNiDvDMgr1.0");System.out.println("");System.out.println("----------------------------------------------------");System.out.println("1.查看DVD");System.out.println("2.借出DVD");System.out.println("3.退出MiNiDvDMgr");System.out.println("");System.out.println("----------------------------------------------------");System.out.println("nn请选择:");intchose=input.nextInt();switch(chose){case1:search();break;case2:lend();break;case3:System.out.println("谢谢使用");break;default:System.out.println("输入错误,退出程序。");}}publicvoidsearch(){System.out.println("nmydvdmgr1.0--->查询dvdn");for(inti=0;i<dvd.name.length;i++){if(dvd.name[i]==null){break;}System.out.print("《"+dvd.name[i]+"》");if(dvd.state[i]==0){System.out.println("tt已借出");}elseSystem.out.println("tt末借出");}}publicvoidreturnmenu(){System.out.println("按0键返回上层目录:");intnum=input.nextInt();if(num==0){startmenu();}else{System.out.println("输入错误,退出程序。");}}publicvoidlend(){System.out.println("nmydvdmgr1.0--->查询dvdn");System.out.println("请输入要借出的DVD名称:");Stringnum=input.next();for(inti=0;i<dvd.name.length;i++){if(dvd.name[i].equals(num)&&dvd.state[i]==1){System.out.println("n可借出n");System.out.println("n成功借出n");dvd.state[i]=0;returnmenu();}elseif(dvd.name[i].equals(num)&&dvd.state[i]==0){System.out.println("n已经借出n");returnmenu();}}}}运行查看DVD正常,但是运行借出也就是lend()类在返回startmenu()的时候选择查看就会出现错误,提示好像是有空对象。那位高手帮我看看
解决方案
解决方案二:
在线等,希望高手们帮帮忙、谢谢了
解决方案三:
if(dvd.name[i]==null)这个空对象是正常的把为什么还会提示错误?