2014-02-13 56 views
0

嗨我做了一個if查詢,並且這個問題發送到服務器。但是,服務器將只接受2個數字和一個十進制數字(99.9),但我必須計數到100,服務器總是給我一個錯誤。 你知不知道我可以怎麼捕捉這個錯誤,以至於我的軟件無論如何Counts爲100.它不能輸出到服務器。該程序只能運行。他不讓它在99再次停止,並繼續倒計時所以當他正值99,然後100我不能發現錯誤

公共靜態無效的主要(字串[] args) {

boolean positive = true; 
    int counter = 0; 


    while (true) 
    { 

     if (counter >= 99) 
     { 
      positive = false; 
     } 
     if (counter <=-99) 
     { 
      positive = true; 
     } 

     if (positive == true) 
     { 
      counter ++; 
     } 
     else 
     { 
      counter --;  
     } 

這是我的「軟件「例外是:

Exception = Response was of unexpected text/html ContentType. Incoming portion of HTML stream: <html><head><title>Apache Tomcat/7.0.47 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - Request processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/QueryTimeoutException</h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u>Request processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/QueryTimeoutException</u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/QueryTimeoutException 
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948) 
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) 
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186) 
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) 
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) 
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) 
</pre></p><p><b>root cause</b> <pre>java.lang.NoClassDefFoundError: org/springframework/dao/QueryTimeoutException 
    org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.&lt;init&gt;(SQLErrorCodeSQLExceptionTranslator.java:86) 
    org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.&lt;init&gt;(SQLErrorCodeSQLExceptionTranslator.java:102) 
    org.springframework.jdbc.support.JdbcAccessor.getExceptionTranslator(JdbcAccessor.java:99) 
    org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605) 
    org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:849) 
    org.springframework.jdbc.core.simple.AbstractJdbcInsert.executeInsertAndReturnKeyHolderInternal(AbstractJdbcInsert.java:436) 
    org.springframework.jdbc.core.simple.AbstractJdbcInsert.executeInsertAndReturnKeyInternal(AbstractJdbcInsert.java:417) 
    org.springframework.jdbc.core.simple.AbstractJdbcInsert.doExecuteAndReturnKey(AbstractJdbcInsert.java:371) 
    org.springframework.jdbc.core.simple.SimpleJdbcInsert.executeAndReturnKey(SimpleJdbcInsert.java:122) 
    de.fraunhofer.iao.sharedefleet.energiemanagement.backend.ChargePointLogDAO.insertChargePointRequest(ChargePointLogDAO.java:65) 
    de.fraunhofer.iao.sharedefleet.energiemanagement.facade.PlugAndChargeFacade.handleHeartbeatRequest(PlugAndChargeFacade.java:55) 
    de.fraunhofer.iao.sharedefleet.energiemanagement.facade.PlugAndChargeFacade.requestChargingState(PlugAndChargeFacade.java:142) 
    de.fraunhofer.iao.sharedefleet.energiemanagement.services.EVSEHeartbeatEndpoint.requestChargingState(EVSEHeartbeatEndpoint.java:34) 
    sun.reflect.GeneratedMethodAccessor143.invoke(Unknown Source) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    java.lang.reflect.Method.invoke(Method.java:606) 
    org.springframework.ws.server.endpoint.MethodEndpoint.invoke(MethodEndpoint.java:134) 
    org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter.invokeInternal(DefaultMethodEndpointAdapter.java:240) 
    org.springframework.ws.server.endpoint.adapter.AbstractMethodEndpointAdapter.invoke(AbstractMethodEndpointAdapter.java:53) 
    org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:233) 
    org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:173) 
    org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:88) 
    org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:59) 
    org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:239) 
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) 
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) 
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186) 
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) 
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) 
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) 
</pre></p><p><b>root cause</b> <pre>java.lang.ClassNotFoundException: org.springframework.dao.QueryTimeoutException. 

所以我希望你能幫助我。

這就是我的主要

public class Main { 





public static void main(String[] args) 
{ 

    boolean positive = true; 
    int counter = 0; 


    while (true) 
    { 

     if (counter >= 99) 
     { 
      positive = false; 
     } 
     if (counter <=-99) 
     { 
      positive = true; 
     } 

     if (positive == true) 
     { 
      counter ++; 
     } 
     else 
     { 
      counter --;  
     } 









     CloudCommunicator ccc = new CloudCommunicator("sh1"); 
     EnergyManagerJob emj = ccc.SendRequest (true , true, 1 , 100 , "Nori2"); 



     System.out.println("\nmax Current: " + emj.allowedMaximumCurrent); 
     System.out.println("charging status: " +emj.chargingPending); 
     System.out.println("power: " +emj.powerOn); 




     try 
     { 
      Thread.sleep(10000); 
     } catch(InterruptedException ex) { 
      Thread.currentThread().interrupt(); 
     } 




    } // end of while 


}// end of main 
+0

您的'main'方法和web應用程序之間有什麼關係? –

+0

聯繫遠程服務器的代碼在哪裏? – Carlo

+0

添加'spring-mvc' lib至少 –

回答

0

爲您發佈的錯誤,你需要find and add the spring-tx library到類路徑中。您可以將其添加到/WEB-INF/lib

但是,我沒有看到您發佈的異常和您發佈的代碼是如何相互關聯的。

+0

我的軟件將數據發送到服務器。我在一個客戶端上工作,服務器不是從我這裏來的。做這個服務器的人已經確定你只能發送一個兩位數的nummer,並且可以在小數點後面傳遞一個數字。但是我想要做的就是捕獲錯誤,以便進一步使我的程序即使服務器報告錯誤100。然後,他應該輸出一個文本輸出,數字100不被服務器接受,但他仍應該繼續返回值數數。 (100)99 98 .... – MQBuild

+0

@ user3297407我希望您明白,您遇到的錯誤與您向我們顯示的代碼完全無關。 –

+0

好的。我無法用錯誤查詢來捕捉它? (例外) – MQBuild

0

索蒂里奧斯Delimanolis是正確的,也請避免把,而(真),因爲它是一個無限循環,你可以把例如while(positive),這會使計數器遞增,直到達到99.