Null pointer exception- but dont know where is my mistake | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Null pointer exception- but dont know where is my mistake

https://code.sololearn.com/c6dccK3sROA3/?ref=app

7th Apr 2023, 1:16 PM
Drelda
Drelda - avatar
3 Answers
+ 4
Drelda use try-catch block maybe then exception will not generate
7th Apr 2023, 2:53 PM
Sakshi
Sakshi - avatar
+ 3
Inventory inventory; public Character(String name, int pozX, int pozY, int power, int def){ super(name); this.pozX=pozX; this.pozY=pozY; this.power=power; this.def=def; this.inventory=inventory; } Here you are setting null data of 'inventory' so you cannot add item in inventory
7th Apr 2023, 3:24 PM
A͢J
A͢J - avatar
+ 1
Thanks AJ, missed that
7th Apr 2023, 3:27 PM
Drelda
Drelda - avatar