JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 如何解決NullPointerException
yanyonyuen





發文: 39
積分: 0
於 2004-04-08 16:52 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我在撰寫一個專題,從資料庫中去得的資料轉成表格之後,要去讀去表格的第一筆資料時會出現錯誤訊息
我的程式碼如下
這是從資料庫中取得的資料,轉換成表格
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<%@ page contentType = "text/html; charset=big5" %>
<%@ page import = "java.sql.* , java.io.* , java.util.*"
     errorPage = "error.jsp" %>
 
<jsp:useBean id = "eng" class = "com.database.Admin"/>
 
<html>
  <head>
    <title>Maintain_table1</title>
  </head>
  <body>
  <form>
    
    <table border = 1>
    <th>編號</th>
    <th>填單日期</th>
    <th>上課教室</th>
    <th>排數</th>
    <th>台數</th>
    <th>維修狀態</th>
      <% 
      eng.connect();
    ResultSet rs = eng.viewtablea();
        while (rs.next()) {
      String number;
      String sysTime;
      String classroom;
      String cpNum1;
      String cpNum2;
      String state;
 
      number = rs.getString("number");
      if(rs.wasNull()) {
        number = null;
      }
    %>
    <tr>
    <td><%= number %></td>
 
    <%
          sysTime = rs.getString("sysTime");
      if(rs.wasNull()) {
        sysTime = null;
      }
    %>
    
    <td><%= sysTime %></td>
 
       <%
          classroom = rs.getString("classroom");
      if(rs.wasNull()) {
        classroom = null;
      }
    %>
    
    <td><%= classroom %></td>
 
     <%
          cpNum1 = rs.getString("cpNum1");
      if(rs.wasNull()) {
        cpNum1 = null;
      }
    %>
    
    <td><%= cpNum1 %></td>
 
     <%
          cpNum2 = rs.getString("cpNum2");
      if(rs.wasNull()) {
        cpNum2 = null;
      }
    %>
    
    <td><%= cpNum2 %></td>
 
     <%
          state = rs.getString("state");
      if(rs.wasNull()) {
        state = null;
      }
    %>
    
    <td><%= state %></td>
      <td>
      <form action = "case_engineer.jsp" method = "POST">
      <input type = "hidden" name = "number" value = '<%= number %>'>
      <input type = "submit" name = "enter" value = "內容">
    </form>
      </td>
    </tr>
    <% } %>
    <% eng.disconnect(); %>
    </table>
  </form>
</body>
</html>


該程式所產生的介面如附件檔案table.jpg

當按下第一筆資料的內容按鈕時,會出現下面的錯誤訊息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
exception:
org.apache.jasper.JasperException
  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
  at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
  at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
  at java.lang.Thread.run(Thread.java:536)
 
root cause:
java.lang.NullPointerException
  at org.apache.jsp.CheckUser_jsp._jspService(CheckUser_jsp.java:62)
  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
  at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
  at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
  at java.lang.Thread.run(Thread.java:536)
 


請問各位前輩要如何解決


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1655 如何解決NullPointerException yanyonyuen 8087 2004-04-08 16:52
1178 Re:如何解決NullPointerException shioulo 72 2004-04-08 19:00
» JWorld@TW »  Servlet/JSP 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8