空指针错误。应该是有对null对象的操作而引起。注意对变量的操作前先判断是否为null

解决方案 »

  1.   

    原代码如下:(各位帮我看看,那错了。)
    <%@ page language="java" %>
    <%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import="java.util.*,java.io.*,java.sql.*,com.hyi.cake.util.*" %>
    <%!
        private String versionInfo = "";
        private String getVersionNumberAndInfo() {
            String versionFileName = "version.htm";
            String versionInfoFileName = "cstore.htm";
            File versionFile = null;
            File versionInfoFile = null;
            Properties props = new Properties();
            String version = null;
            String version_main = null;
            String version_detail = null;
            String tmpPath = "tmp" + File.separator + "deploy" + File.separator
                             + "Default" + File.separator + "estore.ear" + File.separator;
            File jbossHomeDir = new File(".." + File.separator);
            File deployDir = new File(jbossHomeDir, tmpPath);
            String[] deployContent = deployDir.list();
            File estoreWebRootDir = null;
            for (int i = 0; i < deployContent.length; i ++) {
                estoreWebRootDir = new File(deployDir, deployContent[i]);
                if (estoreWebRootDir.isDirectory()) {
                    versionFile = new File(estoreWebRootDir, versionFileName);
                    versionInfoFile = new File(estoreWebRootDir, versionInfoFileName);
                    break;
                }
            }
            if (versionFile != null) {
                try {
                    FileInputStream in = new FileInputStream(versionFile);
                    props.load(in);
                    version_main = props.getProperty("version_main");
                    version_detail = props.getProperty("version_detail");
                    if (version_main != null && version_detail != null) {
                        version = version_main + "." + version_detail;
                    } else {
                        version = "Sorry, the version number can not be got!";
                    }
                } catch (FileNotFoundException e) {
                    version = "Sorry, the version file is corrupt!";
                } catch (IOException e) {
                    version = "Sorry, the IO exception found!";
                }
            } else {
                version = "Sorry, the version file can not be found!";
            }
            if (versionInfoFile != null) {
                try {
                    BufferedReader in = new BufferedReader(new FileReader(versionInfoFile));
                    String s = null;
                    while ((s = in.readLine()) != null) {
                        versionInfo += s + "<br>";
                    }
                } catch (FileNotFoundException e) {
                    versionInfo = "Sorry, the version info file is corrupt!";
                } catch (IOException e) {
                    versionInfo = "Sorry, the IO exception found!";
                }
            } else {
                versionInfo = "Sorry, the version info file can not be found!";
            }
            return version;
        }
    %>
    <%
     String userID = (String)(session.getAttribute("userID"));
        String userName = (String)(session.getAttribute("userName"));
    // write log
     Connection connLog = null;
     java.sql.Statement stLog = null;
     ResultSet rsLog = null;  Calendar curCalendarLog = Calendar.getInstance();
     String nowLog = curCalendarLog.get(Calendar.YEAR)
                + "-" + (curCalendarLog.get(Calendar.MONTH)+1)
                + "-" + curCalendarLog.get(Calendar.DAY_OF_MONTH)
    + " " + curCalendarLog.get(Calendar.HOUR_OF_DAY)
    + ":" + curCalendarLog.get(Calendar.MINUTE)
    + ":" + curCalendarLog.get(Calendar.SECOND);
     
         connLog = CakeConst.getJDBCConnection();
     stLog = connLog.createStatement();
     String sqlLog = "insert into log values(null,'" 
                     + nowLog +"','" + userName + "','0905','1')";
     stLog.executeQuery(sqlLog);  try {
    stLog.close();
    connLog.close();
    } catch (java.sql.SQLException se2) {
    }
     // end of log
    %>
    <p align=left>
    CStore SC Version: <%= getVersionNumberAndInfo() %>
    </p>
    <br>
    <p align=left>
    <%=versionInfo%>
    </p>
      

  2.   

    在version_jsp的getVersionNumberAndInfo里面函数找。
      

  3.   

    在version_jsp的getVersionNumberAndInfo里面函数找。
    不过getVersionNumberAndInfo这个函数比较大,建议你分成几块打几个system.out出来,初步界定一下null的范围。
      

  4.   

    at org.apache.jsp.version_jsp.getVersionNumberAndInfo(version_jsp.java:31):这句话告诉你,你的空指针异常出现在方法getVersionNumberAndInfo里面,具体位置是31行。
    你打开你的编辑器,看看31行是那一行,载你的代码哪儿也没有行的表示。调试的时候,你在代码中加入system.println("");语句,看看到那个地方的那个类是null.
      

  5.   

    看错误一般是第一个错误,你的第一个是 NullPointerException 这个用直译就是 
    “空 指针 异常”就是说你的程序中部分定义参数不可为NULL你应该可以举一反三吧
      

  6.   

    java.lang.NullPointerException //表示出现了什么异常。
            at org.apache.jsp.version_jsp.getVersionNumberAndInfo(version_jsp.java:31)//表示这个异常出现在这个类的这个方法,在31行。
            at org.apache.jsp.version_jsp._jspService(version_jsp.java:142)//表示这个类的这个方法在142行调用的getVersionNumberAndInfo所在的那个方法。下面的依次类推。
            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            ..............