项目中常见NPE空指针异常
Posted 浅殇忆流年
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了项目中常见NPE空指针异常相关的知识,希望对你有一定的参考价值。
项目中常见NPE空指针异常
BigDecimal 转 String
BigDecimal bigDecimal = null;
System.out.println("bigDecimal.toString() = " + bigDecimal.toString());
String 转 BigDecimal
String string = null;
BigDecimal bigDecimal = new BigDecimal(string);
System.out.println("bigDecimal = " + bigDecimal);
List<String> list = null;
String s = list.get(0);
System.out.println("s = " + s);
UserInfo userInfo = null;
String userName = userInfo.getUserName();
System.out.println("userName = " + userName);
String aa = null;
boolean bb = aa.equals("bb");
System.out.println("bb = " + bb);
List<String> strings = null;
List<String> strings1 = Collections.emptyList();
System.out.println("strings = " + strings); // null
System.out.println("strings1 = " + strings1); // []
boolean empty = CollUtil.isEmpty(strings);
boolean empty1 = CollUtil.isEmpty(strings1);
System.out.println("empty = " + empty); // true
System.out.println("empty1 = " + empty1); // true
String str = null;
Map map = new ConcurrentHashMap<>();
map.put(str,"abc");
map.put("aaa",null);
System.out.println("map = " + map);
ZoneInfo zoneInfo = null;
zoneInfo.setName("aaa");
System.out.println("zoneInfo = " + zoneInfo);
以上是关于项目中常见NPE空指针异常的主要内容,如果未能解决你的问题,请参考以下文章