简体   繁体   English

类型不匹配:无法从整数转换为整数

[英]Type mismatch: cannot convert from Integer to int

Thank you for the replies so far. 到目前为止,感谢您的答复。

The exception stack trace is below. 异常堆栈跟踪如下。 As for the java compiler being used, it is whatever is running in Websphere Application Server v6.1 within this version of the tool. 对于正在使用的Java编译器,它是此工具版本中Websphere Application Server v6.1中正在运行的任何东西。 And adding _b resolved the error on some of the lines but not all of them. 并且添加_b解决了某些行中的错误,但不是全部。 I'm not sure that that would be the correct logic to use here. 我不确定这是否是在这里使用的正确逻辑。 But I won't know that until I actually get it running again. 但是,直到我真正让它再次运行,我才知道。 set.Attribute("rowcount",rowcount); set.Attribute( “行数”,行数); also has the first error before and after changing it to set.Attribute("rowcount",rowcount_b); 在将其更改为set.Attribute(“ rowcount”,rowcount_b);之前和之后也都有第一个错误。 So for this variable your solution had no effect. 因此,对于此变量,您的解决方案无效。 Strange. 奇怪。 The whole problem is just strange to me. 整个问题对我来说很奇怪。

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

I had to do the commenting out of these three lines with all of the if statements of this flavor when attempting to apply your suggestion. 在尝试应用您的建议时,我必须使用这种风格的所有if语句对这三行进行注释。 But it did not matter with 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)

I am using ... 我在用 ...

IBM Rational® Application Developer™ for WebSphere® Software 适用于WebSphere®软件的IBMRational®Application Developer™

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

The errors I receive are: 我收到的错误是:

The method setAttribute(String, Object) in the type HttpSession is not applicable for the arguments (String, int) HttpSession类型的方法setAttribute(String,Object)不适用于参数(String,int)

Type mismatch: cannot convert from Integer to int 类型不匹配:无法从整数转换为整数

They occur on these lines: 它们发生在以下行中:

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

Of the following code (snippet): 以下代码(摘要):

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;
        }

This was working before, ie., no runtime errors, so I'm not sure what I messed with just yet to suddenly gain these errors upon clicking "Run on Server1". 这之前是可行的,即没有运行时错误,所以我不确定在单击“在Server1上运行”时突然弄到这些错误的原因。 After noticing the errors 注意到错误后

I set 我设置

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

from its default value of Ignore to Error so that I could see the above lines which were the ones in error. 从其默认值“忽略”到“错误”,这样我可以看到上面几行是错误的。 Because traveling to the java file via 因为通过

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

all the way to the war directory was a bit of a pain :-) (after opening with an editor that shows me the line numbers that were mentioned). 一直到war目录有点痛苦:-)(在打开一个显示我提到的行号的编辑器之后)。

The following 3 lines resolved my problem. 以下3行解决了我的问题。

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

So that after I stored them 这样在我存储它们之后

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

I could retrieve them 我可以找回他们

  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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM