0

guys im wroted this code. When i was writing i have problem when i want to write "e" in argument (void Record). Well Eclipse sugereting me null. I change "e" on "null" but now. When im compiling program has error:

 Exception in thread "main" java.lang.NullPointerException
at javax.swing.SwingUtilities.isLeftMouseButton(SwingUtilities.java:796)
at Clicklu.Clicklu.Action.mousePressed(Action.java:14)
at Clicklu.Clicklu.Action.Record(Action.java:26)
        at Clicklu.Clicklu.Main.main(Main.java:11)


import java.awt.event.MouseEvent;

import javax.swing.SwingUtilities;

public class Action {
LeftMouseClick leftMouseClick = new LeftMouseClick();
RightMouseClick rightMouseClick = new RightMouseClick();

CoursorMove tr = new CoursorMove();

public void mousePressed(MouseEvent e) {
    if (SwingUtilities.isLeftMouseButton(e)) {
        leftMouseClick.addNewLeftMouseClick();
    } else if (SwingUtilities.isRightMouseButton(e)) {
        rightMouseClick.addNewRightMouseClick();
    }
}

public void Record()

{
    for (int i = 0; i < 10000; i++) {
        Action action = new Action();
        action.mousePressed(null);
        tr.gettingMouseCoordinates();

    }

}

public void Play() {
    for (int i = 0; i < 10000; i++) {
        int leftindex = 0;
        int rightindex = 0;
        tr.moveCoursor();

        if (tr.getCoordinate(i).equals(leftMouseClick.getCoordinate(leftindex))) {
            leftMouseClick.leftMouseClick();
            continue;
        }

        else if (tr.getCoordinate(i).equals(rightMouseClick.getCoordinate(rightindex))) {
            rightMouseClick.rightMouseClick();
            continue;
        }

    }

}

}

Main class:

public class Main {

public static void main(String[] args) {
    // CoursorMove triup = new CoursorMove();
    // triup.gettingMouseCoordinates();
    // triup.moveCoursor();



    Action test = new Action();
    test.Record();
    test.Play();

}

}

Brade
  • 17
  • 7
  • Why are you calling `action.mousePressed(null);`? You shouldn't do that. `SwingUtilities.isLeftMouseButton` can't work with a `null` input. – Tunaki Jun 04 '16 at 20:09
  • @Tunaki When i tried to write action.mousePressed(e) eclipse show me error. How i should write it good? – Brade Jun 04 '16 at 20:13
  • I have no idea what you want to do with this code... You're calling Swing methods but you're not using Swing. Why? There's a design issue here. – Tunaki Jun 04 '16 at 20:16
  • `There's a design issue here` - right, so why close the question as a duplicate? That link is one of the worst postings on the forum and will do absolutely nothing to help solve this problem. – camickr Jun 04 '16 at 20:33

0 Answers0