类型不匹配:无法从Integer转换为int

时间:2014-04-08 16:05:17

标签: java eclipse session integer int

感谢您到目前为止的回复。

异常堆栈跟踪如下。对于正在使用的java编译器,它是在此版本的工具中运行的Websphere Application Server v6.1中的任何内容。并且添加_b解决了某些行上的错误,但并非所有行都解决了错误。我不确定这是否是正确的逻辑。但我不会知道,直到我真的让它再次运行。 set.Attribute( “行数”,行数);在将其更改为set.Attribute(“rowcount”,rowcount_b)之前和之后也有第一个错误;因此,对于此变量,您的解决方案无效。奇怪。整个问题对我来说很奇怪。

Integer rowcount_b = (Integer) session.getAttribute("rowcount");  
if (rowcount_b == null) {
    session.setAttribute("rowcount",rowcount_b);
}
// else {
//   rowcount = rowcount_b;
// }

在尝试应用您的建议时,我必须使用这种风格的所有if语句对这三行进行评论。但与rowcount无关。

 at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.translateJsp(AbstractJSPExtensionServletWrapper.java:571)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper._checkForTranslation(AbstractJSPExtensionServletWrapper.java:444)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.checkForTranslation(AbstractJSPExtensionServletWrapper.java:306)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:148)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.handleRequest(AbstractJSPExtensionProcessor.java:295)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3673)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:269)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:831)
    at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1478)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:133)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:457)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:300)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:196)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:751)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:881)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1593)

我正在使用......

用于WebSphere®软件的IBMRational®ApplicationDeveloper™

版本:7.5.5.5 iFix1    内部版ID:RADO7555iFix1-I20120913_1613

我收到的错误是:

HttpSession类型中的方法setAttribute(String,Object)不适用于参数(String,int)

  

类型不匹配:无法从Integer转换为int

它们出现在以下几行:

 session.setAttribute("rowsremaining",rowsremaining);
 rowsremaining = rowsremaining_b;
 session.setAttribute("pos",pos);
 pos = pos_b;

以下代码(摘录):

if (session.getAttribute("searchresults") != null) {   // Tests to make sure the session information was created and passed back from the servlet.
                                                        // If yes, press on, otherwise, display error msg

      ArrayList resultsArray = (ArrayList) session.getAttribute("searchresults");

      if (resultsArray.size()>0) {
         int totaldata = resultsArray.size();  
         int totalrows = totaldata / 10;

         int remainingdata = resultsArray.size(); 
         int rowsremaining = remainingdata/10; 

     // The starting position within the list of returned information

        int pos = 0; 

     // The starting row count - decremented for each row displayed

        int rowcount = 10;  

     // Get the previously stored values of rowsremaining and pos, 
     //if this is the same search, otherwise, they will be as defined above

        Integer rowsremaining_b = (Integer) session.getAttribute("rowsremaining");  
        if (rowsremaining_b == null) {
           session.setAttribute("rowsremaining",rowsremaining);
        }
        else {
          rowsremaining = rowsremaining_b;
        }

        Integer pos_b = (Integer) session.getAttribute("pos");  
        if (pos_b == null) {
           session.setAttribute("pos",pos);
        }
        else {
          pos = pos_b;
        }

这之前有效,即没有运行时错误,所以我不确定我刚刚搞砸了什么    单击“在Server1上运行”时突然获得这些错误。注意到错误后

我设置

Windows --> Preferences --> Java --> Compiler --> Error/Warnings --> Potential Programming Problems --> Boxing and Unboxing conversions

从其默认值Ignore to Error,以便我可以看到上面那些错误的行。因为通过

前往java文件

Program Files --> IBM --> SDP --> runtimes --> base_v61 --> profiles --> was61profile1 --> temp --> node ...

一直到战争目录有点痛苦:-)(在用编辑器打开之后向我展示了提到的行号)。

1 个答案:

答案 0 :(得分:0)

以下3行解决了我的问题。

  pos_b = new Integer(pos);
  rowcount_b = new Integer(rowcount);
  rowsremaining_b = new Integer(rowsremaining);

所以在我存储它们之后

  session.setAttribute("pos",pos_b);
  session.setAttribute("rowsremaining",rowsremaining_b);   
  session.setAttribute("rowcount",rowcount_b);

我可以找回它们

  Integer rowsremaining_b = (Integer) session.getAttribute("rowsremaining");  
    if (rowsremaining_b == null) {
       session.setAttribute("rowsremaining",rowsremaining);
    }
    else {
      rowsremaining = rowsremaining_b;
    }

    Integer pos_b = (Integer) session.getAttribute("pos");  
    if (pos_b == null) {
       session.setAttribute("pos",pos);
    }
    else {
      pos = pos_b;
    }