java.lang.NullPointerException空值异常,你看看你是不是对null对象进行了操作。一般出现在传值取值做处理的时候,把你传的参数的值out.print出来检查一下。

解决方案 »

  1.   

    贴具体的代码出来,可能是使用了NULL值
      

  2.   

    del.jsp:
    <jsp:useBean id="m_idea" class="idea.idea"/>
    <%@page import="java.io.*"%>
    <%
    m_idea.newFilePath="../webapps/guestbook/new.txt";
    m_idea.oldFilePath="../webapps/guestbook/old.txt";
    m_idea.createFile();
    int num=Integer.parseInt(m_idea.readOldFile());
    int i=Integer.parseInt(request.getParameter("i"));
    m_idea.writeNewFile(num-1);
    String m_line="";
    for(int j=1;i<5*num+2;j++)
    {
      m_line=m_idea.readOldFile();
      if(j<=5*(i-1)||j>5*i)
       {
        m_idea.writeNewFile(m_line);
        }
    }
    m_idea.rename();
    %>
    <script language="JavaScript">
    self.location="view.jsp";
    </script>
    idea.java:
    package idea;
    import java.io.*;
    import java.util.*;
    public class idea extends Object
    {
      public String newFilePath="";
      public String oldFilePath="";
      private File newFile;
      private File oldFile;
      private BufferedReader oldFileRead;
      private PrintWriter newFileWrite;
      public boolean flag=true;
      public String systemMessage="";
      public void createFile() throws FileNotFoundException
      {
        newFile=new File(newFilePath);
        oldFile=new File(oldFilePath);
        oldFileRead=new BufferedReader(new FileReader(oldFilePath));
        newFileWrite=new PrintWriter(new FileOutputStream(newFilePath));
      }
      public void writeNewFile(String writeStr) throws FileNotFoundException
      {
        newFileWrite.println(writeStr);
      }
      public void writeNewFile(java.util.Date writeStr) throws FileNotFoundException
      {
        newFileWrite.println(writeStr);
      }
      public void writeNewFile(int writeStr) throws FileNotFoundException
      {
        newFileWrite.println(writeStr);
      }
      public String readOldFile() throws FileNotFoundException
      {
        String readStr="";
        try
        {
    readStr=oldFileRead.readLine();
    if(readStr.equals("<!--end-->"))
      {
        flag=false;
      }
        }
        catch(IOException e)
        { flag=false;
        }
        return readStr;
      }
      public void rename() throws FileNotFoundException
      {
        newFileWrite.close();
        try
        {
    oldFileRead.close();
        }
        catch(IOException e)
        {
    systemMessage=e.toString();
        }
        flag=oldFile.delete();
        flag=newFile.renameTo(oldFile);
      }
    }
    old.txt:
    10
    1
    [email protected]
    11
    111<br>111<br>111
    2003-8-9 16:16:48
    1
    [email protected]
    11
    &lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&amp;&amp;&amp;&lt;&amp;&lt;&lt;br&gt;
    2003-8-9 16:16:14
    1
    [email protected]
    1
    1
    2003-8-9 15:19:53
    dasf
    [email protected]
    adf
    sda
    2003-8-9 15:15:29
    <sd>
    [email protected]
    dsd
    ad<br>ad<br>sd<br>d
    2003-8-9 13:25:00
    "'"ss"
    [email protected]
    """dsd<br>
    adsaa<br>d
    2003-8-9 13:16:03
    fasdf
    [email protected]
    adsf
    fafffffffffffffffffffffffff
    2003-8-9 13:11:27
    esa
    [email protected]
    asdfaa
    sf
    2003-8-9 13:10:48
    sdfs
    [email protected]
    sfd
    sfd
    2003-8-9 12:59:19
    adsf
    [email protected]
    adsfa
    dafaaaaa
    2003-8-8 21:00:36
    <!--end-->
      

  3.   

    int num=Integer.parseInt((String)m_idea.readOldFile());
      

  4.   

    m_idea.readOldFile()返回的就是String型
      

  5.   

    int num=Integer.parseInt(m_idea.readOldFile());
    int i=Integer.parseInt(request.getParameter("i"));估计就应该是这两行的其中一行有问题。判断一下m_idea.readOldFile()和request.getParameter("i")对应的指是否为null