How to fix this error ?

Discussion in 'Plugin Development' started by Minesuchtiiii, Mar 18, 2014.

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

    Minesuchtiiii

    Hey, I am having an issue..
    Im checking if the material is the material which is defined in the config..

    Code:java
    1.  
    2. String material = this.getConfig().getString("TeleportItem");
    3.  
    4. if(e.getItem().getType().equals(Material.getMaterial(material))) {
    5. }


    But im getting errors in the console:

    http://pastebin.com/A4VRNAAA

    What have I done wrong??
    Thanks
     
  2. Offline

    CraftBang

    1. Caused by: java.lang.NullPointerException
    2. at main.HubBukkit.onPlayerInteractWithItemTpItem(HubBukkit.java:460) ~[?:?]
    Line 460, what's wrong with that one (What is line 460)
    And what's in your config
    And did you try a string without the config, so you can easily debug?
     
  3. Code:Java
    1.  
    2. if (e.getItem().getType(Material.getMaterial(material))) {
    3.  
    4. }
    5.  
     
  4. Offline

    Minesuchtiiii

    Techno
    Don'works, getting red lines!
     
  5. Offline

    GameplayJDK

    Minesuchtiiii
    Should work like this:
    Code:java
    1.  
    2. String teleportItem = getConfig().getString("TeleportItem");
    3. if (e.getItem().getType() == Material.getMaterial(teleportItem)) {
    4. // Do stuff here...
    5. }
    6.  

    What does the whole @EventHandler part look like?
     
  6. Offline

    Minesuchtiiii

    CraftBang
    I know how to read the error ^^
    So I posted line 460!!!
    and it's if(e.getItem().getType() == (Material.getMaterial(material))) {}

    GameplayJDK
    Whats the difference? You just gave the string another name... doesn't change anything!

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

    GameplayJDK

    Minesuchtiiii
    So, in case you know how to read the error, as said, you should check if your config is correct, because it seems that the Material.getMaterial(material) returns null, but a material can't be null -> It throws an error.
     
  8. Offline

    Minesuchtiiii

    GameplayJDK It works cause i get the material from the string.. but get an error in console!
     
  9. Offline

    GameplayJDK

    Minesuchtiiii And you get the string from your config. Have you checked if the action is a eight/left click air/block?
     
  10. Offline

    Minesuchtiiii

    GameplayJDK

    Hole event handler:

    Code:java
    1. @EventHandler
    2. public void onPlayerInteractWithTpItem(PlayerInteractEvent e) {
    3. final Player p = e.getPlayer();
    4.  
    5. String material = this.getConfig().getString("TeleportItem");
    6.  
    7. if(e.getAction() == Action.RIGHT_CLICK_AIR | e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    8. if(e.getItem().getType() == Material.getMaterial(material)) {
    9. if(p.hasPermission("serverhub.itemtp")) {
    10.  
    11. if(bo == false && ba == false) {
    12. final FileConfiguration cfg = this.getConfig();
    13.  
    14. if(cfg.get("hubs." + "primary" + ".x") != null) {
    15.  
    16. double x = cfg.getDouble("hubs." + "primary" + ".x");
    17. double y = cfg.getDouble("hubs." + "primary" + ".y");
    18. double z = cfg.getDouble("hubs." + "primary" + ".z");
    19. double yaw = cfg.getDouble("hubs." + "primary" + ".yaw");
    20. double pitch = cfg.getDouble("hubs." + "primary" + ".pitch");
    21. String n = cfg.getString("hubs." + "primary" + ".world");
    22.  
    23. World world = Bukkit.getWorld(n);
    24.  
    25. final Location hubb = new Location(world, x, y, z);
    26. hubb.setYaw((float)yaw);
    27. hubb.setPitch((float)pitch);
    28.  
    29. bo = true;
    30.  
    31. count = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    32.  
    33. @Override
    34. public void run() {
    35.  
    36. if(d != 0) {
    37. p.sendMessage("§7[§cHubTeleport§7] §6Teleporting in §b" + d + " §6seconds!");
    38. d--;
    39.  
    40. } else if(d == 0) {
    41. p.teleport(hubb);
    42. p.sendMessage("§7[§cHubTeleport§7] §6Teleporting...");
    43. d = cfg.getInt("ItemTeleportDelay");
    44. Bukkit.getScheduler().cancelTask(count);
    45. bo = false;
    46. }
    47.  
    48. }
    49.  
    50. }, 0,20L );
    51.  
    52.  
    53. } else {
    54. p.sendMessage(this.px + "§cYou don't have set a primary hub yet!");
    55. return;
    56. }
    57. } else {
    58. return;
    59. }
    60. } else {
    61. p.sendMessage(this.px + "§cYou don't have permissions!");
    62. }
    63. } else {
    64. return;
    65.  
    66. }
    67. } else {
    68. return;
    69. }
    70.  
    71. }
     
  11. Offline

    Voltex

    I'd recommend using type id's when working with this sort of stuff - It's deprecated, but it works fine.
     
  12. Offline

    Minesuchtiiii

    Voltex
    Ya, but for this I'll take the type :/!
     
  13. Offline

    Minesuchtiiii

    bump

    fixed:
    if(p.getItemInHand().equals(material) {

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page