M
M
MakPET2017-02-23 21:30:59
Java
MakPET, 2017-02-23 21:30:59

How can I move the mouse?

I have a laravel project on my server (amazon ec2)
and this java code

import java.awt.event.MouseEvent;
import java.awt.*;

public class Run {

    private static Robot robot = null;

    public static void main(String[] args)
    {
        System.out.println("Hi");
        try{
            robot = new Robot();
        }catch (AWTException e){
            e.printStackTrace();
        }

        klick(250,410);
    }

    public static void klick(int x, int y)
    {
        robot.mouseMove(x,y);       
    }

}

one of the page should run this code and move the mouse but when run it gives this error
Hi
java.awt.AWTException: headless environment
  at java.awt.Robot.<init>(Robot.java:91)
  at Run.main(Run.java:15)
Exception in thread "main" java.lang.NullPointerException
  at Run.klick(Run.java:25)
  at Run.main(Run.java:20)

But at the same time, this code also produces Hi
System.out.println("Hi");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2017-02-24
@zolt85

Well, to top it all off, you have a robot = null variable, which is what is written in the stacktrace. Those. the fall occurs in the click method, when the mouseMove method is called on the robot variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question