關(guān)于其中Student st = students.get(ID);這句的問題
我在使用Eclipse中復(fù)制了視頻中的代碼提示錯(cuò)誤? 錯(cuò)誤提示如下
Exception in thread "main" java.lang.NullPointerException
at com.imooc.Hap.TsetMap.testPut(TsetMap.java:41)
at com.imooc.Hap.TsetMap.main(TsetMap.java:87)
我在使用Eclipse中復(fù)制了視頻中的代碼提示錯(cuò)誤? 錯(cuò)誤提示如下
Exception in thread "main" java.lang.NullPointerException
at com.imooc.Hap.TsetMap.testPut(TsetMap.java:41)
at com.imooc.Hap.TsetMap.main(TsetMap.java:87)
2018-10-15
舉報(bào)
2018-11-21
你的構(gòu)造器的問題,構(gòu)造器是為當(dāng)前對(duì)象進(jìn)行初始化用的,首先構(gòu)造器和類名相同,并且最最最重要的是沒有返回類型,你是不是給構(gòu)造器添加void啦
public 類名(){
this.students = new HashMap<String,Student>();
}
希望我的回答能幫助你哦,么么噠(*  ̄3)(ε ̄ *)
2018-11-21
你的構(gòu)造器的問題,構(gòu)造器是為當(dāng)前對(duì)象進(jìn)行初始化用的,首先構(gòu)造器和類名相同,并且最最最重要的是沒有返回類型,你是不是給構(gòu)造器添加void啦
public 類名(){
this.students = new HashMap<String,Student>();
}
希望我的回答能幫助你哦,么么噠(*  ̄3)(ε ̄ *)
2018-10-17
students是null,是空的,看看你初始化HashMap時(shí)是否有錯(cuò)
2018-10-15
空指針,沒有初始化Student吧