Bukkit Java NullPointer when checking if something is null -
i using bukkit api 1.8.3
i have piece of code:
for(string vey : main.getconfig().getconfigurationsection("shopitems."+key+".enchantments").getkeys(false)) { enchantment ench = enchantment.getbyname(vey); int level = main.getconfig().getint("shopitems."+key+".enchantments."+vey); meta.addenchant(ench, level, true); }
this piece of code gives me nullpointer pointing line starts for-loop iteration.
to try fix have null checker:
if(main.getconfig().getconfigurationsection("shopitems."+key+".enchantments").getkeys(false)!=null)
after null checker put code above inside if statement.
however getting nullpointer on line testing if path null
my question: why not working , how can fix it
note: main.getconfig() returns fileconfiguration not null have tested debugged this
if(main.getconfig().getconfigurationsection("shopitems."+key+".enchantments").getkeys(false)!=null)
is wrong, because when try getkeys(false)
returns null because getconfigurationsection()
null. can fix by:
if(main.getconfig().getconfigurationsection("shopitems."+key+".enchantments") !=null);
Comments
Post a Comment