我想显示没有回帖的帖子,但总是不能成功,这是部分代码:{0}
<%
String author = request.getParameter("author");
List allThreadByName = new ArrayList();
allThreadByName = td.queryThreadsAll();//从所有ThreadsData.java中
Iterator iter = allThreadByName.iterator();
while(iter.hasNext()){
Threads threads = (Threads)iter.next();
int threadid = threads.getThreadid();
String emotionurl = threads.getEmotionurl();
String topic = threads.getTopic();
String description = threads.getDescription();
String authors = threads.getAuthor();
String lastname = threads.getLastname();
String posttime = threads.getPosttime();
String lasttime = threads.getLasttime();
int totalviews = threads.getTotalviews();
int totalreplies = threads.getTotalreplies();
System.out.println("我在topic.jsp中看看totalreplies="+totalreplies);
int threadtop = threads.getThreadtop();
int isgood = threads.getIsgood();
if(smenu.equals("some")){
String postauthor = request.getParameter("author");
if(postauthor.equals(authors)){
%>
<tbody>
<%
 if(threadtop==1){
    %>
    <tr align="center">
    <td style="text-align: left;"><img src="image/topic-pinned.gif" class="topic" /> <%
    if(!emotionurl.equals("wu")){
    %>
   
    <img src=<%=emotionurl%> />
    <%
  }
%>
<font color="#0d00aa"><a href="Posts.jsp?threadid=<%=threadid %>"><%=topic %></a></font></td>
     <td class="author">
     <font color="#0d00aa"><a href="u_datum.jsp?menu=<%=authors %>"><%=authors%></a></font><br>
     <font><%=posttime %></font>
     </td>
    <%
     if(totalreplies>0){
    %>
     <td><font><%=totalreplies %></font></td>
    <%
     }else{
    %>
     <td>-</td>
    <%
     }
     if(totalviews>0){
 %>
     <td><font><%=totalviews %></font></td>
    <%
     }else{
    %>
     <td>0</td>
    <%
     }
    %>
     <td><font><%=lasttime%></font><br>by <font color="#0d00aa"><a href="u_datum.jsp?menu=<%=lastname %>"><%=lastname %></a></font></td>
     </tr>
    <%
    }else{
    %>
     <tr align="center">
    <%
    if(isgood == 0){
%>
     <td style="text-align: left;"><img src="image/topic.gif" /> <%
    if(!emotionurl.equals("wu")){
    %>
   
    <img src=<%=emotionurl%> />
    <%
  }
%> <font color="#0d00aa"><a href="Posts.jsp?threadid=<%=threadid %>"><%=topic %></a></font></td>
    <%
     }else{
    %>
     <td style="text-align: left;"><img src="image/topic-popular.gif" /> <%
    if(!emotionurl.equals("wu")){
    %>
   
    <img src=<%=emotionurl%> />
    <%
  }
%> <font color="#0d00aa"><a href="Posts.jsp?threadid=<%=threadid %>"><%=topic %></a></font></td>
    <%
     }
    %>
     <td>
     <font color="#0d00aa"><a href="u_datum.jsp?menu=<%=authors %>"><%=authors%></a></font><br>
     <font><%=posttime %></font>
     </td>
    <%
     if(totalreplies>0){
    %>
     <td><font><%=totalreplies %></font></td>
    <%
     }else{
    %>
     <td>-</td>
    <%
     }
     if(totalviews>0){
    %>
     <td><font><%=totalviews %></font></td>
    <%
     }else{
    %>
     <td>0</td>
    <%
     }
    %>
     <td><font><%=lasttime%></font><br>by <font color="#0d00aa"><a href="u_datum.jsp?menu=<%=lastname %>"><%=lastname %></a></font></td>
     </tr>
    <%
    }
    }
    %>
</tbody>
<%
}
//从这儿开始是判断回帖数是否为0的帖子 if(smenu.equals("noreversion")){
if(totalreplies<=0){
System.out.println("看看总回帖数totalreplies="+totalreplies);
%>
<tbody>
<%
 if(threadtop==1){
    %>
    <tr align="center">
    <td style="text-align: left;"><img src="image/topic-pinned.gif" class="topic" /> <%
    if(!emotionurl.equals("wu")){
    %>
   
    <img src=<%=emotionurl%> />
    <%
  }
%> <font color="#0d00aa"><a href="Posts.jsp?threadid=<%=threadid %>"><%=topic %></a></font></td>
     <td class="author">
     <font color="#0d00aa"><a href="u_datum.jsp?menu=<%=authors %>"><%=authors%></a></font><br>
     <font><%=posttime %></font>
     </td>
    <%
     if(totalreplies>0){
    %>
     <td><font><%=totalreplies %></font></td>
    <%
     }else{
    %>
     <td>-</td>
    <%
     }
     if(totalviews>0){
 %>
     <td><font><%=totalviews %></font></td>
    <%
     }else{
    %>
     <td>0</td>
    <%
     }
    %>
     <td><font><%=lasttime%></font><br>by <font color="#0d00aa"><a href="u_datum.jsp?menu=<%=lastname %>"><%=lastname %></a></font></td>
     </tr>
    <%
    }else{
    %>
     <tr align="center">
    <%
    if(isgood == 0){
%>
     <td style="text-align: left;"><img src="image/topic.gif" /> <%
    if(!emotionurl.equals("wu")){
    %>
   
    <img src=<%=emotionurl%> />
    <%
  }
%> <font color="#0d00aa"><a href="Posts.jsp?threadid=<%=threadid %>"><%=topic %></a></font></td>
    <%
     }else{
    %>
     <td style="text-align: left;"><img src="image/topic-popular.gif" /> <%
    if(!emotionurl.equals("wu")){
    %>
   
    <img src=<%=emotionurl%> />
    <%
  }
%> <font color="#0d00aa"><a href="Posts.jsp?threadid=<%=threadid %>"><%=topic %></a></font></td>
    <%
     }
    %>
     <td>
     <font color="#0d00aa"><a href="u_datum.jsp?menu=<%=authors %>"><%=authors%></a></font><br>
     <font><%=posttime %></font>
     </td>
    <%
     if(totalreplies>0){
    %>
     <td><font><%=totalreplies %></font></td>
    <%
     }else{
    %>
     <td>-</td>
    <%
     }
     if(totalviews>0){
    %>
     <td><font><%=totalviews %></font></td>
    <%
     }else{
    %>
     <td>0</td>
    <%
     }
    %>
     <td><font><%=lasttime%></font><br>by <font color="#0d00aa"><a href="u_datum.jsp?menu=<%=lastname %>"><%=lastname %></a></font></td>
     </tr>
    <%
    }
    %>
</tbody>
<%
}
}
 
本人在赶毕设,在过2天就答辩了,拜托各位高手帮帮忙!
请大家帮忙分析分析代码,到底哪儿出错了?

解决方案 »

  1.   

    1、smenu是什么值?
    2、建议不要在循环中创建太多变量
      

  2.   

    这个都没问题,因为其他的(查询置顶帖子,我的帖子及精华帖子都能成功),
    肯定是从代码这儿:
    code={0}
    //从这儿开始是判断回帖数是否为0的帖子    if(smenu.equals("noreversion")){
            if(totalreplies<=0){
            System.out.println("看看总回帖数totalreplies="+totalreplies);[/code] 开始出现问题的。
    到底是哪儿出错了,高手帮忙啊???
      

  3.   

    {0}
    //从这儿开始是判断回帖数是否为0的帖子  if(smenu.equals("noreversion")){
      if(totalreplies<=0){
      System.out.println("看看总回帖数totalreplies="+totalreplies); 
      

  4.   

    tangren,你在哪儿了?
    呜呜.....
      

  5.   

    不好意思,我没有贴出出错原因,以下是出错原因:
    conn is:jdbc:oracle:thin:@localhost:1521:gaoyu, UserName=SYSTEM, Oracle JDBC driver
    我在tools.DbConn中数据库连接成功!!
    我在topic.jsp循环输出中看看authors=gaofeng
    我在topic.jsp中看看totalreplies=0
    我在topic.jsp中看看:smenu=noreversion
    看看总回帖数totalreplies=0
    2011-5-21 21:50:54 org.apache.catalina.core.StandardWrapperValve invoke
    严重: Servlet.service() for servlet jsp threw exception
    java.lang.NullPointerException
    at org.apache.jsp.topic_jsp._jspService(topic_jsp.java:770)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at logfilter.EncodingFilter.doFilter(EncodingFilter.java:50)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)
    请大家帮忙解答下,为什么不能显示没有回复的帖子?
      

  6.   


    关键是Myeclipse的跟踪调试,我不会,
    lianghaijian
    你好,你有其他的解决办法吗?
      

  7.   

     if(smenu.equals("noreversion")){
      if(totalreplies<=0){
      System.out.println("看看总回帖数totalreplies="+totalreplies);里面嵌套有if(totalreplies<=0)..这是怎么回事
      

  8.   

     if(smenu.equals("noreversion")){
      if(totalreplies<=0){
      System.out.println("看看总回帖数totalreplies="+totalreplies);里面嵌套有if(totalreplies>0)  这是怎么回事。。
      

  9.   

    你的代码看着让我头痛,因为页面上到处都是java代码。
    既然是topic这个JSP页面上出空异常,
    那么你去看下tomcat目录下的work目录里的topic_jsp.java这个Servlet文件!
    它也告诉你了是770出现异常,而且是在Service里,这样你再找找,你的JSP页面我看的头痛!
      

  10.   


    totalreplies是帖子的总回复数,如果总回复数<=0,那么就说明该帖子没有人回复,就要显示该帖子啊
      

  11.   


    liutianxiong888
    ,你好!
    我不明白这个770是什么意思啊?你能说得详细点吗,谢谢!
      

  12.   

    如果要避免抛空指针异常,先把所有带equals判断的语句修改一下
    如:
    emotionurl.equals("wu") 修改为
    "wu".equals(emotionurl)但这个可能不是最终解决方案,你的代码可能存在逻辑错误。
      

  13.   


    唐大哥,你真是太牛了!
    我的问题,又在一次被你解决了!唐大哥,小弟我希望这2天你能常来java->web版块。
    毕业设计都亮红灯了!
    谢谢唐大哥啊!当然,也谢谢其他的朋友!
      

  14.   

    [Quote=引用 16 楼 ggxxkkll 的回复:]
    引用 12 楼 ncist_jianeng 的回复:
    if(smenu.equals("noreversion")){
    if(totalreplies<=0){
    System.out.println("看看总回帖数totalreplies="+totalreplies);里面嵌套有if(totalreplies<=0)..这是怎么回事
    totalreplies是帖子的总回复……
    你既然判断了totalreplies<=0。。再在这里面嵌套totalreplies>0..这不就矛盾了吗?
      

  15.   

    支持20楼,空指针很多都是string.equals("dsdsd")造成的,以前不习惯写"dsfsdf".equals(string),经常出现空指针,后来慢慢的就习惯了 ,因为很多你认为一定不会报空的数据通常会因为各种原因取不出值,养成写"dsfsdf".equals(string)习惯应该就好了