i wrote javaapplication name javaapplication5 in netbeans gets active window title. code runs in intellij in netbeans gives error (exception in thread "main" java.lang.nosuchmethoderror
). how can execute program in netbeans without error?
package javaapplication5; import com.sun.jna.native; import com.sun.jna.pointer; import com.sun.jna.platform.win32.windef.hwnd; import com.sun.jna.ptr.pointerbyreference; public class javaapplication5 { private static final int max_title_length = 1024; public static void main(string[] args) throws exception { string lasttitle = "none"; string lastprocess = "none"; long lastchange = system.currenttimemillis(); while (true) { string currenttitle = getactivewindowtitle(); string currentprocess = getactivewindowprocess(); if (!lasttitle.equals(currenttitle)) { long change = system.currenttimemillis(); long time = (change - lastchange) / 1000; lastchange = change; system.out.println("change! last title: " + lasttitle + " lastprocess: " + lastprocess + " time: " + time + " seconds"); lasttitle = currenttitle; lastprocess = currentprocess; } try { thread.sleep(1000); } catch (interruptedexception ex) { // ignore } } } private static string getactivewindowtitle() { char[] buffer = new char[max_title_length * 2]; hwnd foregroundwindow = user32dll.getforegroundwindow(); user32dll.getwindowtextw(foregroundwindow, buffer, max_title_length); string title = native.tostring(buffer); return title; } private static string getactivewindowprocess() { char[] buffer = new char[max_title_length * 2]; pointerbyreference pointer = new pointerbyreference(); hwnd foregroundwindow = user32dll.getforegroundwindow(); user32dll.getwindowthreadprocessid(foregroundwindow, pointer); pointer process = kernel32.openprocess(kernel32.process_query_information | kernel32.process_vm_read, false, pointer.getvalue()); psapi.getmodulebasenamew(process, null, buffer, max_title_length); string processname = native.tostring(buffer); return processname; } static class psapi { static { native.register("psapi"); } public static native int getmodulebasenamew(pointer hprocess, pointer hmodule, char[] lpbasename, int size); } static class kernel32 { static { native.register("kernel32"); } public static int process_query_information = 0x0400; public static int process_vm_read = 0x0010; public static native pointer openprocess(int dwdesiredaccess, boolean binherithandle, pointer pointer); } static class user32dll { static { native.register("user32"); } public static native int getwindowthreadprocessid(hwnd hwnd, pointerbyreference pref); public static native hwnd getforegroundwindow(); public static native int getwindowtextw(hwnd hwnd, char[] lpstring, int nmaxcount); } }