今天热门
热点:

服务器发送的int类型,接收到的却是double类型,intdouble


private void personCenter(ReaderInfo info, Socket s) {
String stuNum = info.getReader_number();
// 读者学号
maps.put("stuNum", stuNum);
// 借阅数量
int count = process.countBorrowedBookNumber(stuNum);
maps.put("totalBorrow", count);
// 到期提醒
Map<String, Object> over = process.getFastlyExpiredBorrowedBook(info.getReader_number());
// 到期书籍加上快到期书籍
@SuppressWarnings("unchecked")
int overBook = ((List<String>) (over.get("over"))).size() + ((List<String>) (over.get("fast"))).size();
maps.put("overBook", overBook);
// 签到次数
int loginCount = process.getLoginCountByUser(stuNum);
maps.put("loginCount", loginCount);
// 收藏书单数量
int collection = process.countAllCollectionBookByStuNum(stuNum);
maps.put("collection", collection);
toJsonObject(maps, s);
}

以上是服务器发送map回来,map里有Int数据
客户端:
new Thread(){
public void run() {
                                socket=SocketUtil.createSocket();
SocketUtil.toJsonObject(u, socket);
maps=SocketUtil.jsonObjToBean(ois);
                                int in=(int) maps.get("overBook");
                               System.out.println(in);
};
}.start();

然后就报错,错误代码如下:

解决方案

1.看toJsonObject(maps, s);后的值。

2.SocketUtil.jsonObjToBean(ois)后的值和接收到的值 。

一般之种情况多发于服务器端转换过程中。

maps.put("overBook", overBook);  估计是你这里没有指定类型,  系统给你用了Double类型而不是Integer,
你可以试试在这里, 自己构造一个Integer对象传入.  不让系统帮你自动转换

你上面有个warning你不要去掉。看下警告原因。然后对着比较下借阅数量的数据类型。对比分析下。

没事,接收的是double,如果找不出是哪个地方的问题,你就接收后,再转成int。

www.zrccd.nettrue/topics/20180204/188741.htmlTechArticle服务器发送的int类型,接收到的却是double类型,intdouble privatevoidpersonCenter(ReaderInfoinfo,Sockets){ StringstuNum=info.getReader_number(); //读者学号 maps.put("stuNum",stuNum); //借阅数量 intcount=process.countB...

相关文章

    暂无相关文章

用户评论

大家都在看