Cube Generieren

Dieses Thema im Forum "Programmierung" wurde erstellt von Nexus15, 19. April 2013.

  1. Nexus15
    Offline

    Nexus15

    Registriert seit:
    30. September 2012
    Beiträge:
    91
    Hallo liebe Community,

    leider habe ich ein kleines Problem in meinem Code.
    Ich erhalte eine NullPointerException.

    Code (Text):
    1. public void generatePlot(Location loc, int length, int y) throws InvalidFlagFormat, ProtectionDatabaseException {
    2.         World w = loc.getWorld();
    3.        
    4.         int y_start = loc.getBlockY();
    5.         int x_start = loc.getBlockX();
    6.         int z_start = loc.getBlockZ();
    7.        
    8.         int y_length = y_start + y;
    9.         int x_length = x_start + length;
    10.         int z_length = z_start + length;
    11.        
    12.         for(int x_operate = x_start; x_operate <= x_length; x_operate++) {
    13.            
    14.             for(int y_operate = y_start; y_operate <= y_length; y_operate++) {
    15.                
    16.                 for(int z_operate = z_start; z_operate <= z_length; z_operate++) {
    17.                     Block b = w.getBlockAt(x_operate, y_operate, z_operate);
    18.                     b.setType(Material.GRASS);
    19.                }
    20.             }
    21.         }
    22.     }
    Hier der Log (ausschnitt):

    Code (Text):
    1. Caused by: java.lang.NullPointerException
    2.     at com.hiancou.ClickSign.generatePlot(ClickSign.java:201)
    3.     at com.hiancou.ClickSign.onClick(ClickSign.java:107)
    4.     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    5.     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    6.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    7.     at java.lang.reflect.Method.invoke(Unknown Source)
    8.     at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    9.     ... 16 more
    Zeile 201:

    Code (Text):
    1. Block b = w.getBlockAt(x_operate, y_operate, z_operate);
     
    #1
  2. games6471
    Online

    games6471

    Hast du es schon einmal versucht Debug-Code einzubinden? Dann kannst du nämlich selber nachschauen woher der NPE kommt. Du wirst dein Plugin bestimmt am besten kennen.
     
    #2