I dont understand nullpointerexception?
<p>in my code, for some reason, it randomly shows in the debug window or whatever saying this "nullpointerexception". So I searched around and according to the java website, that means that an object is trying to be initialized without calling it or something of that nature. The problem is, this code works just fine, sometimes it doesn't If someone could take a look at my code, and explain to me where the error is coming from, and why that would be great! Here is the code:</p>

<p>EDIT: Also I cant post the direct error sinces it randomly shows up, but maybe a nullpointer is an error you see just by looking at code! ALL I KNOW IS THAT IT THE ERROR IS IN THE CODE 'clikc.mouse(xYCoords);' So it must have something to do with the 'xYCoords' thing.</p>

<p>HERE IS THE ERROR IN THE DEBUG:</p>

<pre><code>java.lang.NullPointerExeption

at net.xotiksys.api.methods.input.Mouse.click(Mouse,java: 213)
at AutoGemmer.clickShop(AutoGemmer.java: 42)
at AutoGemmer.script(AutoGemmer.java: 93)
at net.xotiksys.api.ActiveScript.run(ActivrScript.java: 149)
at java.lang.Thread.run(Unknown Source)
</code></pre>

<p>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ERROR^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>

<pre><code>import java.awt.*;
import java.awt.Point;
import java.awt.Color;

import javax.swing.*;
import javax.swing.JFrame;

import net.xotiksys.api.methods.recognition.ColorRecognition;
import net.xotiksys.api.painting.Paintable;
import net.xotiksys.api.ActiveScript;
import net.xotiksys.api.Manifest;
import net.xotiksys.api.methods.input.Mouse;
import net.xotiksys.api.util.*;
import net.xotiksys.api.methods.recognition.Colors;
import net.xotiksys.Application;
import net.xotiksys.api.wrappers.DTM;

@Manifest(author = "iwrestledabearonce", description = "Buys and chisels dragonstones into bolt tips.", name = "Auto Gemmer", version = 2.0)
public class AutoGemmer extends ActiveScript implements Paintable {

    private static final Point dragonStone = new Point(284, 225);
    private static final Point openShop = new Point(275, 136);
    private static final Point click10 = new Point(281, 299);
    private static final Point closeShop = new Point(467, 40);
    private static final Point chisel = new Point(707, 447);
    private static final Point inv = new Point(669, 446);
    private static final Color MOUSE_COLOR = new Color(165, 55, 0, 100);
    private static final Color COLOR_TO_CLICK = new Color(142, 30, 18);
    private static Point xYCoords = null;

    public boolean shop = false;
    public boolean buy = false;
    public boolean cut = false;

    public int gemsCut = 0;
    public String botStatus = "";


    protected int clickShop() {
            Point xYCoords = Colors.getPosition(COLOR_TO_CLICK);
            Mouse.setSpeed(10);
            Mouse.click(xYCoords, true);
                try {
                    Thread.sleep(2000);
                    } catch(InterruptedException e) {
                        System.out.println(e);
                }
            botStatus = "Buying Gems....";
            buy = true;
            shop = false;
            return -1;
    }

    public void buyGems() {
            Mouse.setSpeed(10);
            Mouse.hop(dragonStone);
            Mouse.click(dragonStone, false);
            Mouse.click(click10, true);
            Mouse.hop(dragonStone);
            Mouse.click(dragonStone, false);
            Mouse.click(click10, true);
            Mouse.hop(dragonStone);
            Mouse.click(dragonStone, false);
            Mouse.click(click10, true);
            Mouse.hop(closeShop);
            Mouse.click(closeShop, true);
            try {
            Thread.sleep(3000);
            } catch(InterruptedException e) {
                    System.out.println(e);
        }
            buy = false;
            cut = true;
    }   

    public void makeBolts() {
        while (gemsCut &lt;= 51) {
            botStatus = "Cutting Dragonstones....";
            Mouse.hop(chisel);
            Mouse.click(chisel, true);
            Mouse.hop(inv);
            Mouse.click(inv, true);
            gemsCut += 1;
        }
        while (gemsCut &gt;= 51) {
            cut = false;
            gemsCut = 0;
        }
    }

    @Override
    public int script() {
                clickShop();
                if(buy == true) {
                    buyGems();
                }
                    if(cut == true) {
                        makeBolts();
                    }
            return 0;
    }

    public void paint(final Graphics g) {
                g.setColor(Color.CYAN);
                g.drawString("Status: "+botStatus, 150, 330);
        }
}
</code></pre>
