java - variable not null then turns null? -


this question has answer here:

so have file manager class handles data being loaded , saved. reason when declare file manager used in class turns null when test file manager via debug messages, shows as, not null. reason when use declaration shows null.

[16:21:22 error]: error occurred while enabling creditcard v1.0 (is  date?) java.lang.nullpointerexception     @ com.dogboy602k.creditcard.main.util.manager.<init>(manager.java:47) ~[?:?]     @ com.dogboy602k.creditcard.main.main.main.onenable(main.java:42) ~[?:?]     @ org.bukkit.plugin.java.javaplugin.setenabled(javaplugin.java:292) ~[spigot.jar:git-spigot-e50d38c-02f4218]     @ org.bukkit.plugin.java.javapluginloader.enableplugin(javapluginloader.java:340) [spigot.jar:git-spigot-e50d38c-02f4218]     @ org.bukkit.plugin.simplepluginmanager.enableplugin(simplepluginmanager.java:405) [spigot.jar:git-spigot-e50d38c-02f4218]     @ org.bukkit.craftbukkit.v1_10_r1.craftserver.loadplugin(craftserver.java:362) [spigot.jar:git-spigot-e50d38c-02f4218]     @ org.bukkit.craftbukkit.v1_10_r1.craftserver.enableplugins(craftserver.java:322) [spigot.jar:git-spigot-e50d38c-02f4218]     @ org.bukkit.craftbukkit.v1_10_r1.craftserver.reload(craftserver.java:746) [spigot.jar:git-spigot-e50d38c-02f4218]     @ org.bukkit.bukkit.reload(bukkit.java:539) [spigot.jar:git-spigot-e50d38c-02f4218]     @ org.bukkit.command.defaults.reloadcommand.execute(reloadcommand.java:25) [spigot.jar:git-spigot-e50d38c-02f4218]     @ org.bukkit.command.simplecommandmap.dispatch(simplecommandmap.java:141) [spigot.jar:git-spigot-e50d38c-02f4218]     @ org.bukkit.craftbukkit.v1_10_r1.craftserver.dispatchcommand(craftserver.java:646) [spigot.jar:git-spigot-e50d38c-02f4218]     @ org.bukkit.craftbukkit.v1_10_r1.craftserver.dispatchservercommand(craftserver.java:632) [spigot.jar:git-spigot-e50d38c-02f4218]     @ net.minecraft.server.v1_10_r1.dedicatedserver.al(dedicatedserver.java:437) [spigot.jar:git-spigot-e50d38c-02f4218]     @ net.minecraft.server.v1_10_r1.dedicatedserver.d(dedicatedserver.java:400) [spigot.jar:git-spigot-e50d38c-02f4218]     @ net.minecraft.server.v1_10_r1.minecraftserver.c(minecraftserver.java:672) [spigot.jar:git-spigot-e50d38c-02f4218]     @ net.minecraft.server.v1_10_r1.minecraftserver.run(minecraftserver.java:571) [spigot.jar:git-spigot-e50d38c-02f4218] 

file manager:

public class filemanager { private main plugin; private arraylist <uuid> list = new arraylist(); private arraylist <string> rlist = new arraylist();  public filemanager(main plugin) {     this.plugin = plugin;     sendconsolemessage.debug("pl: "+plugin); }  //extra code } 

main:

public class main extends javaplugin { private manager manager; private economy economy = null; private filemanager filemanager; private commands commands; private plugin plugin = this; public void onenable() {     file configfile;     this.filemanager = new filemanager(this);     if(getfilemanager() == null){         sendconsolemessage.debug("its null");     }     this.manager = new manager(this);     this.commands = new commands(this);     this.setupeconomy();      this.getcommand("creditcard").setexecutor(new commands(this));     file playerdatafile = new file(this.getdatafolder(), "playerdata.yml");     if (!playerdatafile.exists()) {         this.getfilemanager().savedefaultconfiguration(playerdatafile);     }     file rewarddatafile = new file(this.getdatafolder(), "rewards.yml");     if (!rewarddatafile.exists()) {         this.getfilemanager().savedefaultconfiguration(rewarddatafile);     }     if (!(configfile = new file(this.getdatafolder(), "config.yml")).exists()) {         this.savedefaultconfig();     }     this.filemanager.loadrewarddata();     this.filemanager.loadplayerdata();      bukkit.getpluginmanager().registerevents(this.manager, this);     this.getmanager().addintrest();     manager.resentthemaxpoints();     manager.autopayexecute(); } 

manager:

public class manager implements listener { private main plugin; private messagemanager mm; private player p; private list<maxloan> loan; private list<cardinfo> cardinfos = new arraylist<cardinfo>(); private list<rewardinfo> rewards = new arraylist<rewardinfo>(); private int pinholder; private double debt, points; private string passwordholder; private double loanamount1 = 0.0; private double payoff1 = 0.0; private int gperspin = 0; private player gowner = null; private arraylist<uuid> uuids = new arraylist(); private arraylist<player> overdueplayerson = new arraylist<player>(); private arraylist<offlineplayer > overdueplayersoff = new arraylist<offlineplayer>(); private int count =0; filemanager f = plugin.getfilemanager(); //this imports premade msgs private string hasnotregistered = f.gethasnotregistered() ,wrongpassword= f.getwrongpassword(),alreadyregisterd= f.getalreadyregisterd(),notenoughcashtopay= f.getnotenoughcashtopay(),         payamountoverdebt= f.getpayamountoverdebt(), wrongpin= f.getwrongpin(), maxloanreached= f.getmaxloanreached(),maxpointsreached= f.getmaxpointsreached(), wantloanlargerthanlimit= f.getwantloanlargerthanlimit(), commanddidntsayall= f.getcommanddidntsayall(),         donthaveenoughtopayalldebt= f.getdonthaveenoughtopayalldebt(),debtcantbepaiditszero= f.getdebtcantbepaiditszero(),payamountlessthanzero= f.getpayamountlessthanzero(), notenoughpoints= f.getnotenoughpoints(),loanlessthanzero= f.getloanlessthanzero() ; private string foundpin= f.getfoundpin(),registered= f.getregistered(),autopaymsg= f.getautopaymsg(), moneyisbeingadded= f.getmoneyisbeingadded(), newtotalpoints= f.getnewtotalpoints(), youhavezerodebtppayinzerodays= f.getyouhavezerodebtppayinzerodays(),         overdeadline= f.getoverdeadline(), youownamountindays= f.getyouownamountindays(), pleasewait= f.getpleasewait(), howmuchispaidoff= f.gethowmuchispaidoff(), youhavepoints= f.getyouhavepoints(),pointsdescription= f.getpointsdescription(),         yougotreward= f.getyougotreward(), closedguimenu= f.getclosedguimenu(),pointsyoucanget= f.getpointsyoucanget(),couldnotfindreward= f.getcouldnotfindreward(),joinmsgnodebt= f.getjoinmsgnodebt(),joinmsg= f.getjoinmsg(); public manager(main plugin) {     this.plugin = plugin;     this.loan = new arraylist<maxloan>(); } 

that because declared plugin without initializing in manager class

class manager {      ...      private main plugin;      filemanager f = plugin.getfilemanager();      ... } 

i suggest add constructor manager class , initialize plugin , filemanager

something :

public manager() {     this.plugin = new main();     filemanager f = plugin.getfilemanager(); } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -