问题描述
HTTPStatus500---------------------------------------------------------------------------------typeExceptionreportmessagedescriptionTheserverencounteredaninternalerror()thatpreventeditfromfulfillingthisrequest.exceptionorg.apache.jasper.JasperException:java.lang.NullPointerExceptionorg.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rootcausejava.lang.NullPointerExceptionnumb1.com.onLine.delUser(onLine.java:17)numb1.com.onLine.addUser(onLine.java:53)org.apache.jsp.first_jsp._jspService(first_jsp.java:211)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/6.0.18logs.--------------------------------------------------------------------------------ApacheTomcat/6.0.18db.java代码packagenumb1.com;importjava.lang.*;importjava.sql.*;publicclassdb{privateConnectioncon;privateStatementst;privateResultSetrs;privateStringhost="localhost";privateStringuser="root";privateStringpw="123456";privateStringdb="numb1";privateStringDri="com.mysql.jdbc.Driver";privateStringurl="jdbc:mysql://"+host+"/"+db;publicStringgetStr(Strings){Stringstr=s;try{byteb[]=str.getBytes("ISO-8859-1");str=newString(b);returnstr;}catch(Exceptione){returnnull;}}publicStringgb2iso(Stringqs){try{if(qs==null)return"NULL";elsereturnnewString(qs.getBytes("gb2312"),"iso-8859-1");}catch(Exceptione){System.out.print("gb2isoerror:"+e.getMessage());}return"NULL";}publicvoidclose(){//关闭连接try{if(rs!=null)rs.close();}catch(Exceptione){System.out.print("rs"+e.getMessage());}try{if(st!=null)st.close();}catch(Exceptione){System.out.print("st"+e.getMessage());}try{if(con!=null)con.close();}catch(Exceptione){System.out.print("con"+e.getMessage());}}publicResultSetquery(Stringsql)throwsException{try{Class.forName(Dri).newInstance();con=DriverManager.getConnection(url,user,pw);st=con.createStatement();rs=st.executeQuery(sql);returnrs;}catch(SQLExceptione){System.out.print(e.getMessage());returnnull;}}publicvoidupdate(Stringsql)throwsException{try{Class.forName(Dri).newInstance();con=DriverManager.getConnection(url,user,pw);st=con.createStatement();st.executeUpdate(sql);st.close();con.close();}catch(SQLExceptione){System.out.print(e.getMessage());}}}online.java代码packagenumb1.com;importjava.util.ArrayList;importjava.util.Date;publicclassonLine{ArrayList<String>User=newArrayList<String>();publicvoiddelUser(longonTime){DatenowTime=newDate();Longl;for(inti=0;i<User.size();i+=5){try{l=Long.getLong(User.get(i+4));if(nowTime.getTime()/1000-l.intValue()>=onTime){User.remove(i);User.remove(i);User.remove(i);User.remove(i);User.remove(i);}}catch(ArrayIndexOutOfBoundsExceptione){}catch(ClassCastExceptione){}}User.trimToSize();}publicvoidaddUser(StringuId,StringuName,StringuPage,StringuIP,longonTime){DatenowTime=newDate();Longl=newLong(nowTime.getTime()/1000);for(inti=0;i<User.size();i+=5){try{if(uId.compareTo((String)User.get(i))==0&&uIP.compareTo((String)User.get(i+3))==0){User.remove(i);User.remove(i);User.remove(i);User.remove(i);User.remove(i);break;}}catch(ArrayIndexOutOfBoundsExceptione){}catch(ClassCastExceptione){}}User.add(uId);User.add(uName);User.add(uPage);User.add(uIP);User.add(l.toString());delUser(onTime);}publicbooleanLogin(StringuId,StringuIP){for(inti=0;i<User.size();i+=5){try{if(uId.compareTo((String)User.get(i))==0)returnfalse;if(((String)User.get(i)).compareTo("guest")==0&&uIP.compareTo((String)User.get(i+3))==0){User.remove(i);User.remove(i);User.remove(i);User.remove(i);User.remove(i);break;}}catch(ArrayIndexOutOfBoundsExceptione){}}returntrue;}publicvoidShut(StringuId){for(inti=0;i<User.size();i+=5){try{if(((String)User.get(i)).compareTo(uId)==0){User.remove(i);User.remove(i);User.remove(i);User.remove(i);User.remove(i);break;}}catch(ArrayIndexOutOfBoundsExceptione){}}}publicintgCount(){returnUser.size()/5;}publicintgUCount(){intn=0;for(inti=0;i<User.size();i+=5){try{if(((String)User.get(i)).compareTo("guest")!=0){n++;}}catch(ArrayIndexOutOfBoundsExceptione){}}returnn;}publicintgThisCount(Stringboardid){String[]str=getuPage();intn=0;for(inti=0;i<str.length;i++){try{if(str[i].substring(str[i].lastIndexOf("=")+1).compareTo(boardid)==0){n++;}}catch(StringIndexOutOfBoundsExceptione){}}returnn;}publicString[]getuId(){String[]str=newString[User.size()/5];intn=0;for(inti=0;i<User.size();i+=5){try{str[n++]=(String)User.get(i);}catch(ArrayIndexOutOfBoundsExceptione){}}returnstr;}publicString[]getuName(){String[]str=newString[(User.size()/5)];intn=0;for(inti=1;i<User.size();i+=5){try{str[n++]=(String)User.get(i);}catch(ArrayIndexOutOfBoundsExceptione){}}returnstr;}publicString[]getuPage(){String[]str=newString[(User.size()/5)];intn=0;for(inti=2;i<User.size();i+=5){try{str[n++]=(String)User.get(i);}catch(ArrayIndexOutOfBoundsExceptione){}}returnstr;}publicString[]getuIP(){String[]str=newString[(User.size()/5)];intn=0;for(inti=3;i<User.size();i+=5){try{str[n++]=(String)User.get(i);}catch(ArrayIndexOutOfBoundsExceptione){}}returnstr;}}
解决方案
解决方案二:
空子针,没有改对象你却使用,肯定报错User.remove(i)怎么这么多啊他的大小是改变的,如果他的大小为5,那他的索引为0-4,删掉一个后就为0-3了,没有改索引你怎么去用他指定元素啊
解决方案三:
不好意思,请问怎么改啊
解决方案四:
publicvoiddelUser(longonTime){DatenowTime=newDate();Longl;if(User.size()>0){for(inti=0;i<User.size();i+=5){//每次加5是干嘛用的,就不能加1吗,如果加5好多元素都不会读到try{l=Long.getLong(User.get(i+4));//不知道你这个是来干嘛的,但肯定会越界if(nowTime.getTime()/1000-l.intValue()>=onTime){User.remove(i);}}catch(ArrayIndexOutOfBoundsExceptione){}catch(ClassCastExceptione){}}}User.trimToSize();}
解决方案五:
boss,要不我把整个程序发给你,帮我改下我看了一个晚上,都蛋疼了~!我qq:527776698~!您无聊就帮帮我吧~!