asp技术网站开发案例,房屋设计图软件免费,文山seo公司,施工企业排名java中的NullPointerException异常关注:176 答案:3 mip版解决时间 2021-01-27 20:59提问者侢遇噹姩揂2021-01-27 02:10Login.jsp提供登录表单。到LoginCheck.jsp发生空指针异常错误。LoginCheck.jsp:String userName request.getParameter(userName);String pas…java中的NullPointerException异常关注:176 答案:3 mip版解决时间 2021-01-27 20:59提问者侢遇噹姩揂2021-01-27 02:10Login.jsp提供登录表单。到LoginCheck.jsp发生空指针异常错误。LoginCheck.jsp:String userName request.getParameter(userName);String passward request.getParameter(passward);if(userName.length()0passward.length()0){session.setAttribute(status,Login);response.sendRedirect(Main.jsp);}elseresponse.sendRedirect(Login.jsp);%最佳答案二级知识专家無字情書2021-01-27 02:52String userName request.getParameter(userName); //这里取值的时候 有可能会取到 nullString passward request.getParameter(passward); //这里取值的时候 有可能会取到 nullif(userName.length()0passward.length()0) //如果这里 userName null || passward nul,你引用字符串的 length() 方法的时候就会 出现异常了因为 字符串对象不存在却引用了他的方法最好 加一下判断 不为空的时候 判断字符串长度{1、if(userName!nullpassward!nulluserName.length()0passward.length()0)2、或者接受参数的时候就做调整String userName request.getParameter(userName) null ? :request.getParameter(userName) ;String passward request.getParameter(passward) null :request.getParameter(passward);全部回答1楼久别无恙2021-01-27 05:01最好还是发异常的控制台输出的信息吧那个描述非常清晰看一眼就知道是哪个类、哪个方法、哪一行出的问题。如果没有输出定位信息用try-catch捕捉一下。2楼薯片软妹2021-01-27 03:44因为目录有可能是空目录即目录下没有文件所以path.list() 返回为null,所以需要在for循环前判断一下加一句if(files!null)就行了。完整的程序如下import java.io.file;import java.io.ioexception;public class traverse {public static void tra(file path){if(path null){return;}if(path.isdirectory()){string[] files path.list();if(files!null) //这里加一句for(int i 0; i files.length;i){tra(new file(path,files[i]));}}else if(path.getabsolutepath().endswith(.mp3)){system.out.println(path);}}public static void main(string[] args) {try{file file new file(d:\\);tra(file);}catch(exception e){e.printstacktrace();}}}我要举报如以上问答内容为低俗/色情/暴力/不良/侵权的信息可以点下面链接进行举报我们会做出相应处理感谢你的支持→点此我要举报以上信息←推荐资讯大家都在看