httpclient --- NullPointerException

12 篇文章 0 订阅
7 篇文章 0 订阅
@RequestMapping("/user/send/")
	@ResponseBody
	public int addMsgUser(Long ids,HttpServletRequest request)throws Exception{
		log.debug("cuntroller++++++++++++++"+ids.toString()+"==============="+ids.intValue());
		HttpSession session = request.getSession();
		MsgUser msgUser = msgUserService.getMsgUserById(ids);
		Object object = session.getAttribute("ids");		
		if(object!=null){		
			return 0;
		}
		session.setAttribute("ids", msgUser.getLimitcount());
		session.setMaxInactiveInterval(60/msgUser.getLimitcount());	
		int	i = msgUserService.sendPhone(ids);	
		return i;	
	}HttpSession session = request.getSession();
		MsgUser msgUser = msgUserService.getMsgUserById(ids);
		Object object = session.getAttribute("ids");		
		if(object!=null){		
			return 0;
		}
		session.setAttribute("ids", msgUser.getLimitcount());
		session.setMaxInactiveInterval(60/msgUser.getLimitcount());	
		int	i = msgUserService.sendPhone(ids);	
		return i;	
	}
@Override
	public MsgUser getMsgUserById(Long ids) {
		MsgUser user = msgUserMapper.selectByPrimaryKey(ids);
		return user;
	}
 @Override
	public int updateMsgUser(MsgUser user) {
		int i = msgUserMapper.updateByPrimaryKeySelective(user);
		return i;
	}
@Override
	public int sendPhone(Long ids )throws Exception{
		MsgUserExample example = new MsgUserExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdEqualTo(ids);
		List<MsgUser> list = msgUserMapper.selectByExample(example);
		for (MsgUser ls : list) {
			log.debug(ls.getId());
		}		
		 for(int  i=0;i<list.size();i++){
                         //NullPointerException
			 int sendcount = list.get(i).getSendcount();	
			 //sendcount= sendcount.longValue();
			 sendcount+=1;	
			 int sumcount = list.get(i).getSumcount();
			 sumcount-=1;					 
			 if(sumcount<=0){
				 break;
			 }
			/* list.get(i).setSumcount(sumcount);
			 list.get(i).setSendcount(sendcount);*/
			 //更新数据
			 MsgUser user = this.getMsgUserById(ids);
			 user.setSendcount(sendcount);
			 user.setSumcount(sumcount); 
			 int msgUser = this.updateMsgUser(user);
			 String phone = list.get(i).getMobile();
			 sendPhone(phone);	
		 }		 
		 return list.size();
	}int sendcount = list.get(i).getSendcount();	
			 //sendcount= sendcount.longValue();
			 sendcount+=1;	
			 int sumcount = list.get(i).getSumcount();
			 sumcount-=1;					 
			 if(sumcount<=0){
				 break;
			 }
			/* list.get(i).setSumcount(sumcount);
			 list.get(i).setSendcount(sendcount);*/
			 //更新数据
			 MsgUser user = this.getMsgUserById(ids);
			 user.setSendcount(sendcount);
			 user.setSumcount(sumcount); 
			 int msgUser = this.updateMsgUser(user);
			 String phone = list.get(i).getMobile();
			 sendPhone(phone);	
		 }		 
		 return list.size();
	}
public  void sendPhone(String phone) throws Exception{
		/*通过后台请求远程服务,同意AJAX传到服务端,服务端得到电话,生产随机数一份发送到服务商,另一份村渠道session
		 * 跟注册的页面返回一个结果  */ 		
		CloseableHttpClient client= HttpClients.createDefault();
		//HttpPost post = new  HttpPost("http://yzm.mb345.com/ws/BatchSend2.aspx?CorpID=XALKY01114&Pwd=fr@1114&Mobile=186XXX&Content=你的验证码是12345,在2分钟内有效。如非本人操作请忽略本短信。");
		HttpPost post = new HttpPost("http://yzm.mb345.com/ws/BatchSend2.aspx");
		ArrayList<NameValuePair> list = new ArrayList<NameValuePair> ();
		list.add(new BasicNameValuePair("CorpID", "XALKY01114"));
		list.add(new BasicNameValuePair("Pwd", "fr@1114"));
		list.add(new BasicNameValuePair("Mobile", phone));
		String number=RandomValue.getRandomChar(5, 3);
		String demo ="你的验证码为"+number+"在3分钟内有效。如非本人操作请忽略本短信。";
		list.add(new BasicNameValuePair("Content", demo));
		UrlEncodedFormEntity entity=new UrlEncodedFormEntity(list,"UTF-8");
		post.setEntity(entity);
		 CloseableHttpResponse response = client.execute(post);
		log.debug("code===="+response.getStatusLine().getStatusCode()); 
		log.debug("entity===="+EntityUtils.toString(response.getEntity(),"UTF-8"));
		response.close();
		client.close();
		
	}
 

今天的一个项目,service 传输数据一直空指针异常 (java.lang.NullPointerException) ,开始以为是数据转换的问题,最后原因是数据库没有默认值为NULL,

把一个值为null的值赋予另一个值,对象也为NULL,就会一直NullPointerException

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值