gpt4 book ai didi

java - 类型不匹配 : cannot convert from Integer to int

转载 作者:太空宇宙 更新时间:2023-11-04 14:58:11 25 4
gpt4 key购买 nike

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

异常堆栈跟踪如下。至于所使用的 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 语句对这三行进行注释。但这与行数无关。

 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)

我正在使用...

IBM Rational® Application Developer™ for WebSphere® Software

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

我收到的错误是:

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

Type mismatch: cannot convert from Integer to 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;
}

这之前是有效的,即没有运行时错误,所以我不确定我搞砸了什么 但在单击“Run on Server1”时突然出现这些错误。注意到错误后

我设置了

Windows --> 首选项 --> Java --> 编译器 --> 错误/警告 --> 潜在的编程问题 --> 装箱和拆箱转换

从其默认值“忽略”更改为“错误”,以便我可以看到上面的行是错误的。因为通过

前往 java 文件

程序文件 --> IBM --> SDP --> 运行时 --> base_v61 --> 配置文件 --> was61profile1 --> 临时 --> 节点 ...

一直到 war 目录有点痛苦:-)(用编辑器打开后,显示了提到的行号)。

最佳答案

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

关于java - 类型不匹配 : cannot convert from Integer to int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22942368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com