正确写法
<%String[][] blog = new String[5][]; blog[0] = request.getParameterValues("blog0"); blog[1] = request.getParameterValues("blog1"); blog[2] = request.getParameterValues("blog2"); blog[3] = request.getParameterValues("blog3"); blog[4] = request.getParameterValues("blog4"); for(int i=0;i<blog.length;i++){ if(blog[i]==null){ blog[i]=new String[5]; blog[i][0]="博客题目"; blog[i][1]="博客分类"; blog[i][2]="博客时间"; blog[i][3]="博客前80字"; } %>
不能写作
<%String[][] blog = new String[5][5]; blog[0] = request.getParameterValues("blog0"); blog[1] = request.getParameterValues("blog1"); blog[2] = request.getParameterValues("blog2"); blog[3] = request.getParameterValues("blog3"); blog[4] = request.getParameterValues("blog4"); for(int i=0;i<blog.length;i++){ if(blog[i]==null){ blog[i][0]="博客题目"; blog[i][1]="博客分类"; blog[i][2]="博客时间"; blog[i][3]="博客前80字"; } %>
否则会报
Stacktrace:] with root cause
java.lang.NullPointerException
即blog[i][0]="博客题目";指针找不到错误。