ExceptionInInitializerError onEnable

Discussion in 'Plugin Development' started by ZonalYewHD, Jun 18, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ZonalYewHD

    I just finished a voting plugin, but I keep getting the ExceptionInInitializerError when I enable it. I know how to read stack-traces, but I don't see what the error is. The full stack trace is here.

    The VeritasVoting class is below.

    Code:java
    1. package me.zonalyewhd.veritasvoting;
    2.  
    3. import me.zonalyewhd.veritasvoting.commands.Nominate;
    4. import me.zonalyewhd.veritasvoting.commands.Tools;
    5. import me.zonalyewhd.veritasvoting.commands.Vote;
    6.  
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class VeritasVoting extends JavaPlugin {
    10.  
    11. public void onEnable() {
    12. saveDefaultConfig();
    13. System.out.println("VeritasVoting has been enabled!");
    14. getCommand("vote").setExecutor(new Vote());
    15. getCommand("nominate").setExecutor(new Nominate());
    16. getCommand("tools").setExecutor(new Tools());
    17. }
    18.  
    19. public void onDisable() {
    20. System.out.println("VeritasVoting has now been disabled!");
    21. }
    22.  
    23. private static VeritasVoting instance;
    24.  
    25. public static VeritasVoting getInstance() {
    26. return instance;
    27. }
    28.  
    29. }
    30.  


    The Vote class:
    Code:java
    1. package me.zonalyewhd.veritasvoting.commands;
    2.  
    3. import static org.bukkit.ChatColor.BLUE;
    4. import static org.bukkit.ChatColor.DARK_AQUA;
    5. import static org.bukkit.ChatColor.DARK_PURPLE;
    6. import static org.bukkit.ChatColor.DARK_RED;
    7. import static org.bukkit.ChatColor.GREEN;
    8. import static org.bukkit.ChatColor.LIGHT_PURPLE;
    9. import static org.bukkit.ChatColor.RED;
    10. import static org.bukkit.ChatColor.WHITE;
    11. import static org.bukkit.ChatColor.YELLOW;
    12.  
    13. import java.util.List;
    14.  
    15. import me.zonalyewhd.veritasvoting.VeritasVoting;
    16. import me.zonalyewhd.veritasvoting.utils.VoteUtils;
    17.  
    18. import org.bukkit.Bukkit;
    19. import org.bukkit.command.Command;
    20. import org.bukkit.command.CommandExecutor;
    21. import org.bukkit.command.CommandSender;
    22. import org.bukkit.entity.Player;
    23.  
    24. public class Vote implements CommandExecutor {
    25.  
    26. private void saveConfig() {
    27. VeritasVoting.getInstance().saveConfig();
    28. }
    29.  
    30. private void reloadConfig() {
    31. VeritasVoting.getInstance().reloadConfig();
    32. }
    33.  
    34. private List<String> vipNominated = VeritasVoting.getInstance().getConfig()
    35. .getStringList("nominations.vip");
    36.  
    37. private List<String> vipGoldNominated = VeritasVoting.getInstance()
    38. .getConfig().getStringList("nominations.vipgold");
    39.  
    40. private List<String> vipPlatinumNominated = VeritasVoting.getInstance()
    41. .getConfig().getStringList("nominations.vipplatinum");
    42.  
    43. private List<String> modNominated = VeritasVoting.getInstance().getConfig()
    44. .getStringList("nominations.mod");
    45.  
    46. private List<String> adminNominated = VeritasVoting.getInstance()
    47. .getConfig().getStringList("nominations.admin");
    48.  
    49. private List<String> staffNominated = VeritasVoting.getInstance()
    50. .getConfig().getStringList("nominations.most-helpful-staff");
    51.  
    52. private String noNominations = RED + "There are no nominations for "
    53. + DARK_RED + "%rank%" + RED + " at this time!";
    54.  
    55. private String notNominated = RED + "That player has not been nominated!";
    56.  
    57. private String noPerm = RED + "Your ability to vote has been revoked.";
    58.  
    59. private String playerVoteVIPPerm = "vv.vote.vip";
    60.  
    61. private String playerVoteVIPGoldPerm = "vv.vote.vipgold";
    62.  
    63. private String playerVoteVIPlatinumPerm = "vv.vote.vipplatinum";
    64.  
    65. private String playerVoteModPerm = "vv.vote.mod";
    66.  
    67. private String playerVoteAdminPerm = "vv.vote.admin";
    68.  
    69. private String playerVoteStaffPerm = "vv.vote.staff";
    70.  
    71. private List<String> adminVote = VeritasVoting.getInstance().getConfig()
    72. .getStringList("voted.admin");
    73.  
    74. private List<String> modVote = VeritasVoting.getInstance().getConfig()
    75. .getStringList("voted.mod");
    76.  
    77. private List<String> vipVote = VeritasVoting.getInstance().getConfig()
    78. .getStringList("voted.vip");
    79.  
    80. private List<String> vipGoldVote = VeritasVoting.getInstance().getConfig()
    81. .getStringList("voted.vipgold");
    82.  
    83. private List<String> vipPlatinumVote = VeritasVoting.getInstance()
    84. .getConfig().getStringList("voted.vipplatinum");
    85.  
    86. private List<String> staffVote = VeritasVoting.getInstance().getConfig()
    87. .getStringList("voted.most-helpful-staff");
    88.  
    89. private String alreadyVoted = RED + "You have already voted for "
    90. + DARK_RED + "%rank%";
    91.  
    92. @SuppressWarnings("deprecation")
    93. public boolean onCommand(CommandSender sender, Command cmd, String s,
    94. String[] args) {
    95. if (args.length != 1) {
    96. sender.sendMessage(RED
    97. + "Invalid arguments! Use either a player or rank!");
    98. } else {
    99. if (!(sender instanceof Player)) {
    100. sender.sendMessage("You must be a player to vote!");
    101. } else {
    102. Player player = (Player) sender;
    103.  
    104. if (args[0].equalsIgnoreCase("vip")) {
    105. if (vipNominated.isEmpty()) {
    106. player.sendMessage(noNominations.replaceAll("%rank%",
    107. "VIP"));
    108. } else {
    109. player.sendMessage(GREEN + "VIP Nominations:");
    110. for (String nominee : vipNominated) {
    111. player.sendMessage(" " + DARK_AQUA + nominee);
    112. }
    113. }
    114. } else if (args[0].equalsIgnoreCase("vipgold")) {
    115. if (vipGoldNominated.isEmpty()) {
    116. player.sendMessage(noNominations.replaceAll("%rank%",
    117. "VIPGold"));
    118. } else {
    119. player.sendMessage(YELLOW + "VIPGold Nominations:");
    120. for (String nominee : vipGoldNominated) {
    121. player.sendMessage(" " + DARK_AQUA + nominee);
    122. }
    123. }
    124. } else if (args[0].equalsIgnoreCase("vipplatinum")) {
    125. if (vipPlatinumNominated.isEmpty()) {
    126. player.sendMessage(noNominations.replaceAll("%rank%",
    127. "VIPlatinum"));
    128. } else {
    129. player.sendMessage(WHITE + "VIP Nominations:");
    130. for (String nominee : vipPlatinumNominated) {
    131. player.sendMessage(" " + DARK_AQUA + nominee);
    132. }
    133. }
    134. } else if (args[0].equalsIgnoreCase("mod")) {
    135. if (modNominated.isEmpty()) {
    136. player.sendMessage(noNominations.replaceAll("%rank%",
    137. "Mod"));
    138. } else {
    139. player.sendMessage(DARK_PURPLE + "Mod Nominations:");
    140. for (String nominee : modNominated) {
    141. player.sendMessage(" " + DARK_AQUA + nominee);
    142. }
    143. }
    144. } else if (args[0].equalsIgnoreCase("admin")) {
    145. if (adminNominated.isEmpty()) {
    146. player.sendMessage(noNominations.replaceAll("%rank%",
    147. "Admin"));
    148. } else {
    149. player.sendMessage(BLUE + "VIP Nominations:");
    150. for (String nominee : adminNominated) {
    151. player.sendMessage(" " + DARK_AQUA + nominee);
    152. }
    153. }
    154. } else if (args[0].equalsIgnoreCase("staff")) {
    155. if (staffNominated.isEmpty()) {
    156. player.sendMessage(noNominations.replaceAll("%rank%",
    157. "Most Helpful Staff"));
    158. } else {
    159. player.sendMessage(LIGHT_PURPLE
    160. + "Most Helpful Staff Nominations:");
    161. for (String nominee : staffNominated) {
    162. player.sendMessage(" " + DARK_AQUA + nominee);
    163. }
    164. }
    165. } else {
    166. Player selection = Bukkit.getPlayer(args[1]);
    167. String playerName = player.getName();
    168. String selectionName = selection.getName();
    169. String rankName = VoteUtils.getRank(selectionName);
    170. if (rankName == null) {
    171. player.sendMessage(notNominated);
    172. } else {
    173. if (rankName == "vip") {
    174. if (player.hasPermission(playerVoteVIPPerm)) {
    175. if (vipVote.contains(playerName)) {
    176. player.sendMessage(alreadyVoted.replaceAll(
    177. "%rank%", rankName));
    178. } else {
    179. VoteUtils.vote(selectionName, playerName);
    180. saveConfig();
    181. reloadConfig();
    182. }
    183. } else {
    184. player.sendMessage(noPerm);
    185. }
    186. } else if (rankName == "vipgold") {
    187. if (player.hasPermission(playerVoteVIPGoldPerm)) {
    188. if (vipGoldVote.contains(playerName)) {
    189. player.sendMessage(alreadyVoted.replaceAll(
    190. "%rank%", rankName));
    191. } else {
    192. VoteUtils.vote(selectionName, playerName);
    193. saveConfig();
    194. reloadConfig();
    195. }
    196. } else {
    197. player.sendMessage(noPerm);
    198. }
    199. } else if (rankName == "viplatinum") {
    200. if (player.hasPermission(playerVoteVIPlatinumPerm)) {
    201. if (vipPlatinumVote.contains(playerName)) {
    202. player.sendMessage(alreadyVoted.replaceAll(
    203. "%rank%", rankName));
    204. } else {
    205. VoteUtils.vote(selectionName, playerName);
    206. saveConfig();
    207. reloadConfig();
    208. }
    209. } else {
    210. player.sendMessage(noPerm);
    211. }
    212. } else if (rankName == "mod") {
    213. if (player.hasPermission(playerVoteModPerm)) {
    214. if (modVote.contains(playerName)) {
    215. player.sendMessage(alreadyVoted.replaceAll(
    216. "%rank%", rankName));
    217. } else {
    218. VoteUtils.vote(selectionName, playerName);
    219. saveConfig();
    220. reloadConfig();
    221. }
    222. } else {
    223. player.sendMessage(noPerm);
    224. }
    225. } else if (rankName == "admin") {
    226. if (player.hasPermission(playerVoteAdminPerm)) {
    227. if (adminVote.contains(playerName)) {
    228. player.sendMessage(alreadyVoted.replaceAll(
    229. "%rank%", rankName));
    230. } else {
    231. VoteUtils.vote(selectionName, playerName);
    232. saveConfig();
    233. reloadConfig();
    234. }
    235. } else {
    236. player.sendMessage(noPerm);
    237. }
    238. } else if (rankName == "staff") {
    239. if (player.hasPermission(playerVoteStaffPerm)) {
    240. if (staffVote.contains(playerName)) {
    241. player.sendMessage(alreadyVoted.replaceAll(
    242. "%rank%", rankName));
    243. } else {
    244. VoteUtils.vote(selectionName, playerName);
    245. saveConfig();
    246. reloadConfig();
    247. }
    248. } else {
    249. player.sendMessage(noPerm);
    250. }
    251. } else {
    252. for (Player p : Bukkit.getOnlinePlayers()) {
    253. p.kickPlayer("A serious error occurred with Veritas Voting. Report to Zonal ASAP");
    254. }
    255. Bukkit.shutdown();
    256. System.out
    257. .println("A serious, possibly fatal error has occurred. Report to Zonal ASAP.");
    258. System.out.println("Check Vote.java line: 168");
    259. System.out
    260. .println("A player returned with a 'null' rank and was not caught by the first check.");
    261. }
    262. }
    263. }
    264.  
    265. }
    266. }
    267. return true;
    268. }
    269.  
    270. }
    271.  
     
  2. Offline

    ferrybig

    You never set your static plugin field, this will return null in your vote class
     
  3. Offline

    ZonalYewHD

  4. Offline

    ZonalYewHD

    Anyone?
     
  5. Offline

    fireblast709

    ZonalYewHD remove all the static in your plugin
     
  6. Offline

    ZonalYewHD

    fireblast709 It gives me errors saying that they can't make a static reference to the non-static method, even though there are no more static methods

    fireblast709 I get this error for every method I import from another class

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  7. Offline

    fireblast709

    ZonalYewHD that is why you should remove all static keywords, even from your methods, and learn how to use constructors to pass variables to other classes
     
    xTigerRebornx likes this.
  8. Offline

    ZonalYewHD

Thread Status:
Not open for further replies.

Share This Page