Using GWT and elemental, I have some problem with a null instance. Here is code:
import elemental.events.Event;
import elemental.events.EventListener;
import elemental.html.Window;
import elemental.html.Worker;
public void go()
{
Window window=elemental.client.Browser.getWindow();
Worker worker=window.newWorker("task.js");
EventListener eventListener=new EventListener()
{
#Override
public void handleEvent(Event event)
{
}
}
System.out.println("worker : "+worker+" eventListener : "+eventListener+" window : "+window);
worker.setOnmessage(eventListener);
}
The display is:
worker : [object Worker] eventListener : mainpackage.client.MainClass$1#565f81ea window : [object Window]
So the worker is not null, but I have the error within setOnmessage:
com.google.gwt.core.client.JavaScriptException: (String) : Invoking an instance method on a null instance
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.createJavaScriptException(ModuleSpace.java:80)
at com.google.gwt.dev.shell.ModuleSpace.createJavaScriptException(ModuleSpace.java:64)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:60)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:304)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at elemental.js.html.JsWorker$.setOnmessage$(JsWorker.java)
at com.google.gwt.core.client.JavaScriptObject$.elemental_html_Worker_setOnmessage(JavaScriptObject.java)
at mainpackage.client.MainClass.go(MainClass.java:41)
at mainpackage.client.Testthread.onModuleLoad(Testthread.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:411)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)
Why is there a null instance? How do I solve that? Thanks in advance.
com.google.gwt.core.client.JavaScriptException: (String) : Invoking an instance method on a null instance
This line has an Answer.
As you are trying to invoke
worker.setOnmessage(eventListener);
Worker worker=window.newWorker("task.js");
worker Object is NULL.
So please check whether your newWorker method is actually returning Worker object or not.
Related
I am trying to make a simple RMI execution engine to run on my local machine so that other java programs can easily run code on a second processor. (In the future this will be expanded to allow more processors).
The server starts up just fine, and the client appears to locate the registry ok, but when it tries to call the execution engine (and passes it a parameter) it causes a ClassNotFoundException.
I recognize that this is similar to many other questions on stack overflow, but as far as I can tell, all the other ones have to do with the client not being able to download the server's classes rather than the server not being able to download the client's classes.
Here is my code (copied almost exactly from this sample code):
RMIServer eclipse project
ComputeEngine Interface:
package interfaces;
import java.io.Serializable;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface ComputeEngine_IF extends Remote {
/**
* #param task The task object specifying the computation to be performed
* #return
* #throws RemoteException
*/
<T extends Serializable> T compute(TaskWithoutInput<T> task) throws RemoteException;
}
TaskWithoutInput interface:
package interfaces;
import java.io.Serializable;
public interface TaskWithoutInput<T> extends Serializable {
public T compute();
}
ComputeEngine Class:
package server;
import interfaces.ComputeEngine_IF;
import interfaces.TaskWithoutInput;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class ComputeEngine implements ComputeEngine_IF{
public ComputeEngine() {
super();
}
#Override
public <T extends Serializable> T compute(TaskWithoutInput<T> task) throws RemoteException {
return task.compute();
}
public static void main(String[] args) {
if(System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
String name = "Compute";
ComputeEngine_IF engine = new ComputeEngine();
ComputeEngine_IF stub = (ComputeEngine_IF) UnicastRemoteObject.exportObject(engine, 0);
Registry registry = LocateRegistry.createRegistry(1099);
registry.rebind(name, stub);
System.out.println("Registry bound!");
}
catch (Exception e) {
System.err.println("ComputeEngine exception:");
e.printStackTrace();
}
}
}
RMIClient eclipse project
GetAnswerTask class
package client;
import interfaces.TaskWithoutInput;
public class GetAnswerTask implements TaskWithoutInput<Integer> {
private static final long serialVersionUID = 1L;
#Override
public Integer compute() {
return Integer.valueOf(42);
}
}
Client class
package client;
import interfaces.ComputeEngine_IF;
import interfaces.TaskWithoutInput;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class RmiClientExample {
public static void main(String args[]) {
if(System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
String name = "Compute";
Registry registry = LocateRegistry.getRegistry("localhost");
ComputeEngine_IF comp = (ComputeEngine_IF) registry.lookup(name);
TaskWithoutInput<Integer> getAnswer = new GetAnswerTask();
Integer answer = comp.compute(getAnswer);
System.out.println("Answer: " + answer);
}
catch (Exception e) {
System.err.println("RmiClientExample exception:");
e.printStackTrace();
}
}
}
Both projects contain an identical security policy file (in RMIServer it is called server.policy and in RMIClient it is called client.policy)
grant {
permission java.security.AllPermission;
};
I will, of course, restrict the permissions more once I get this working.
Building/Running
Since the code is pretty close to something I copied out of an example, my guess is that the code is right, or at least close, but that my mistake is in compiling/running the code. The example wasn't written for eclipse, so I don't have exact instructions.
The first thing I did was use eclipse's jar export wizard to jar the interface package into Interfaces.jar which I just placed in my RMIServer folder.
Then I run ComputeEngine with the following defines:
-Djava.rmi.server.codebase=file:/c:/Users/nate/workspace/RMIServer/Interfaces.jar
-Djava.rmi.server.hostname=localhost
-Djava.security.policy=c:/Users/nate/workspace/RMIServer/src/server.policy
The compute engine seems to run just find and outputs the print statement in the code.
I then run the client with the defines:
-Djava.rmi.server.codebase=file:/c:/Users/nate/workspace/RMIClient/bin/
-Djava.security.policy=c:/Users/nate/workspace/RMIClient/src/client.policy
And I get the following error message:
RmiClientExample exception:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: client.GetAnswerTask
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy0.compute(Unknown Source)
at client.RmiClientExample.main(RmiClientExample.java:24)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: client.GetAnswerTask
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: client.GetAnswerTask
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler$Loader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClassForName(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source)
at sun.rmi.server.UnicastServerRef.unmarshalParametersUnchecked(Unknown Source)
at sun.rmi.server.UnicastServerRef.unmarshalParameters(Unknown Source)
... 13 more
Any thoughts on what I might be doing wrong?
GetAnswerTask implements Serializable, so it will be serialized to the server when you call ComputeEngine_IF.compute(). So GetAnswerTask needs to be available at the server, on its classpath, and it isn't.
For those still struggling with oracle RMI tutorial, whose server doesn't download serializable class from given client's codebase (and stubbornly seeks class in its own codebase) - try to add
-Djava.rmi.server.useCodebaseOnly=false
to server's arguments
I've been trying to understand what the issue is exactly, but whatever I do doesn't seem to work.
I have a text file that lists names along with numbers, seperated by a colon.
An example of this is:
Betty Ross:52
Angie Scotts:29
Michael Rosen:72
The list is very long and comprises over 10,000 lines.
public class PeopleIds {
public static int UNDEFINED_ID = -1;
private static HashMap<String, Integer> people;
public static void initialize() {
people = new HashMap<String, Integer>();
System.out.println(new File("res/ids/people_ids.txt").exists());
try {
Files.lines(Paths.get("res/ids/people_ids.txt")).forEach(s -> {
people.put(s.replaceAll(":.*", "").trim(), Integer.parseInt(s.replaceAll(".*:", "")));
});
} catch (IOException e) {
System.out.println("Unable to read specified file.");
e.printStackTrace();
}
}
public static int getId(final String name) {
final Integer id = people.get(name);
return id != null ? id : UNDEFINED_ID;
}
}
I call the initialize method from a GUIController class:
public class GUIController implements Initializable {
#FXML
private TableView<PersonData> personTable;
#FXML
private TableColumn<PersonData, String> name;
#FXML
private TableColumn<PersonData, Integer> limit;
#FXML
private TextField searchInput;
#FXML
private ImageView personIcon;
private Image undefinedIcon;
private PersonIcon icon;
private ObservableList<PersonData> data;
#Override
public void initialize(URL location, ResourceBundle resources) {
PeopleIds.initialize();
undefinedIcon = new Image(getClass().getResourceAsStream("/ids/no.png"));
name.setCellValueFactory(new PropertyValueFactory<PersonData, String>("name"));
limit.setCellValueFactory(new PropertyValueFactory<PersonData, Integer>("limit"));
data = PriceData.getData();
personTable.setPeople(data);
searchInput.textProperty().addListener((ov, oldValue, newValue) -> {
final String input = searchInput.getText();
if (input.length() == 0) return;
searchInput.setText(input.substring(0, 1).toUpperCase() + input.substring(1).toLowerCase());
filterSearch();
});
}
}
When I call it from this class with PeopleIds.initialize(), an exception is thrown, telling me that there was an exception in the application start method.
Here is what was logged in its entirety:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException:
/C:/Confidential/bin/base/PersonGUI.fxml
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at base.PersonGUI.start(PersonGUI.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source)
... 1 more
Caused by: java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
at java.io.BufferedReader$1.hasNext(Unknown Source)
at java.util.Iterator.forEachRemaining(Unknown Source)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
at java.util.stream.ReferencePipeline$Head.forEach(Unknown Source)
at base.PeopleIds.initialize(PeopleIds.java:17)
at base.GUIController.initialize(GUIController.java:36)
... 18 more
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
... 24 more
Exception running application base.PersonGUI
I'm not sure what is going on here? I've looked into it and people have said to move the fxml file (the one that is used to format the content and is linked with the GUIController to the same package as the Main class, however it already is.
I've been wrestling with this issue for days to no avail. Do any of you have past experiences with this issue? If so, how did you resolve it? Thanks a lot.
If there is an Exception while the file is being read, not when opening the file, an unchecked exception is thrown for the Files.lines stream operation (Stream.forEach doesn't have a throws clause).
This happens here
Files.lines(Paths.get("res/ids/people_ids.txt")).forEach(s -> {
people.put(s.replaceAll(":.*", "").trim(), Integer.parseInt(s.replaceAll(".*:", "")));
});
, which you can easily see in the stacktrace:
Caused by: java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
(This is caused by the wrong Charset being used, see Files.readAllBytes vs Files.lines getting MalformedInputException )
You don't catch this kind of exception with your catch clause:
} catch (IOException e) {
You need to use
} catch (Exception e) {
to catch the unchecked exceptions too.
I have this controller class for showing a database query in a TableView, but i am having error of NullPointerException with the "setCellValueFactory(new PropertyValueFactory"
package aplicativo;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
public class Controle implements Initializable{
#FXML
private TextField txtCampo,txtCampo2;
#FXML
private Button btAdicionar,btConsultar;
#FXML
private TableView<Pessoa> tabValues;
#FXML
private TableColumn<Pessoa, Integer> tbcCod;
private TableColumn<Pessoa, String>tbcNome;
ObservableList<Pessoa> List = FXCollections.observableArrayList();
#FXML
private void btAdd(){
insertBD a = new insertBD(txtCampo.getText());
consultaBD b = new consultaBD();
List = b.consultaTudo();
tabValues.setItems(List);
txtCampo.clear();
}
#FXML
private void btCons(){
String tx = txtCampo2.getText();
if(tx.isEmpty()){
}else{
consultaBD a = new consultaBD();
a.consultaParecido(tx, "nome");
txtCampo2.clear();
}
}
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
tbcCod.setCellValueFactory(new PropertyValueFactory<Pessoa, Integer>("cod"));
tbcNome.setCellValueFactory(new PropertyValueFactory<Pessoa, String>("nome"));
tabValues.setItems(List);
tabValues.getColumns().addAll(tbcCod,tbcNome);
}
}
The NullPointerExcepetion:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$50/1645995473.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException:
/C:/Users/lucas/workspace/BDFX/bin/aplicativo/Tela.fxml
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at aplicativo.Main.start(Main.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$53/1031257736.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/186276003.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1529876784.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/237061348.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown Source)
... 1 more
Caused by: java.lang.NullPointerException
at aplicativo.Controle.initialize(Controle.java:52)
... 23 more
Exception running application aplicativo.Main
Any solution?
One of the instance fields in your controller is lacking an #FXML annotation. Since the field is private, the FXML loader is unable to inject the control reference into the field during loading. Here are your instance field declarations:
#FXML
private TextField txtCampo,txtCampo2;
#FXML
private Button btAdicionar,btConsultar;
#FXML
private TableView<Pessoa> tabValues;
#FXML
private TableColumn<Pessoa, Integer> tbcCod;
private TableColumn<Pessoa, String>tbcNome;
Notice that the last field, tbcNome, is not annotated. As a result, when your initialize method is called, the tbcNome field contains a null reference, resulting in the exception.
To fix your problem, all you may need to do is add the #FXML annotation to the instance field declaration for tbcNome.
You may have encouraged this error by adopting the habit of listing more than one variable in your type declarations, eg. private Button btAdicionar, btConsultar;. In my opinion, this is a bad habit that can encourage errors like this to happen. I would suggest that you try to adopt the coding style in which each instance field has its own type declaration statement.
I got the following exception when i tried to do frame.setvisible(true);
java.lang.reflect.InvocationTargetException at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
com.myapp.GeneralEventProc.cmdProc(GeneralEventProc.java:43)
at tcl.lang.Parser.evalObjv(Parser.java:810) at
tcl.lang.Parser.eval2(Parser.java:1209) at
tcl.lang.Interp.eval(Interp.java:2042) at
tcl.lang.Interp.eval(Interp.java:2071) at
javaapps.JScriptProcessor.processCurrentScript(JScriptProcessor.java:389)
at
javaapps.JScriptProcessor.processQueuedScripts(JScriptProcessor.java:632)
at javaapps.JSPThread.run(JSPThread.java:43) Caused by:
java.lang.NullPointerException at
java.awt.FlowLayout.layoutContainer(Unknown Source) at
java.awt.Container.layout(Unknown Source) at
java.awt.Container.doLayout(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validate(Unknown Source) at
java.awt.Window.show(Unknown Source) at
java.awt.Component.show(Unknown Source) at
java.awt.Component.setVisible(Unknown Source) at
java.awt.Window.setVisible(Unknown Source) at
com.myapp.mylist.makeList(Unknown Source) at
com.myapp.mylist.show(MyList.java:144)
The source code is :
public void makeList() {
synchronized (initLock) {
System.out.println(" locking... makeList");
if (_myFrame != null) {
initiateList();
_myFrame .setVisible(true);
} else {
System.out.println("myframe is null");
}
}
}
private void initiateList() {
_myFrame.getContentPane().setLayout(null);
_myFrame.getContentPane().removeAll();
_myapp.setBounds(0, 0, getWidth(), (int) (getHeight() * 0.90));
_myFrame.getContentPane().add(_myapp);
_myFrame.getContentPane().add(_myPanel);
_myPanel.setBounds(0, (int) (getHeight() * 0.90), getWidth(), (int) (getHeight() * 0.10));
_myFrame.validate();
_myFrame.repaint();
}
In the above code two methods makeList(), initiateList().
From makeList() method we are calling initiateList() method after checking the _myFrame is not null within synchronized. Then after returning from the method when i do _myFrame.setVisible(true); the NPE occurs.
Note: This issue happened once and its not reproducible.
Is there any bug in java layer?
Please help me out of this.
Thanks in advance.
This _mainFrame.getContentPane().setLayout(null); would seem to be the start of your problems.
Calling validate instructs the layout manager that it should update the layout of the components under it's control, so I'm not sure why you're calling it or what you hope to achieve.
Is it a bug? That's debatable. Swing is designed around the use of layout managers, so there is an expectation that a layout manager is in use, especially when you call a method intended to update it...I would say, no, it's not a bug...
My program seems to work quite well, but I keep getting "IllegalStateExceptions: RunnableQueue not started or has exited" from time to time, when I try to resize my component. I have set the documentState to ALWAYS_DYNAMIC and I have read that you are supposed to use the JSVGCanvas' UpdateManager and call invokelater(). I understand that it is available after the first time that
gvtBuildCompleted(GVTTreeBuilderEvent e)
is called, so I check whether it is running before I use it but I still get the exception.
The following method is called by a thread repeatedly and seems to cause the exception:
private void updateDomTree(final SVGComponent component, final Document doc)
{
if(component.getSvgCanvas().getUpdateManager() != null && component.getSvgCanvas().getUpdateManager().isRunning())
{
component.getSvgCanvas().getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable()
{
public void run()
{
final Node newNode = doc.getChildNodes().item(0).getFirstChild();
//could be easier to get this value, but ... it works.
String newNodeId = newNode.getAttributes().getNamedItem("id").getFirstChild().getNodeValue();
NodeList nodes = component.getSvgDocument().getDocumentElement().getChildNodes();
Node updateNode = findElementById(nodes, newNodeId);
resizeComponent(component, doc);
component.getSvgCanvas().getSVGDocument().adoptNode(newNode);
component.getSvgCanvas().getSVGDocument().getDocumentElement().replaceChild(newNode, updateNode);
component.refreshSVGCanvas();
}
});
}
}
The actual resizing is done here:
protected void resizeComponent(SVGComponent component, Document doc)
{
Element svgRoot = doc.getDocumentElement();
final int svgWidth = Integer.parseInt(svgRoot.getAttribute("width"));
final int svgHeight = Integer.parseInt(svgRoot.getAttribute("height"));
String[] viewBox = svgRoot.getAttribute("viewBox").split(" ");
int viewBoxLeft = Integer.parseInt(viewBox[0]);
int viewBoxTop = Integer.parseInt(viewBox[1]);
final float factor = component.getScaleFactor();
String[] viewBoxOld = component.getSvgDocument().getDocumentElement().getAttribute("viewBox").split(" ");
int viewBoxLeftOld = Integer.parseInt(viewBoxOld[0]);
int viewBoxTopOld = Integer.parseInt(viewBoxOld[1]);
int xDiff = (int) ((viewBoxLeftOld - viewBoxLeft)*factor);
int yDiff = (int) ((viewBoxTopOld - viewBoxTop)*factor);
if ( viewBoxLeftOld != viewBoxLeft ) //If there is additional content left
{
component.setLocation(component.getLocation().x - xDiff, component.getLocation().y);
}
if ( viewBoxTopOld != viewBoxTop ) //If there is additional content right)
{
component.setLocation(component.getLocation().x, component.getLocation().y - yDiff);
}
component.getSvgDocument().getDocumentElement().setAttribute("width",""+svgWidth);
component.getSvgDocument().getDocumentElement().setAttribute("height",""+svgHeight);
component.getSvgDocument().getDocumentElement().setAttribute("viewBox", ""+viewBoxLeft+" "+viewBoxTop+" "+svgWidth+" "+svgHeight);
component.setSize((int)(svgWidth*factor),(int)(svgHeight*factor));
}
The method
refreshJSVGCanvas()
calls
JSVGCanvas.setDocument(Document);
JSVGCanvas.setSize(int, int);
Here's the full stack trace:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: RunnableQueue not started or has exited
at org.apache.batik.util.RunnableQueue.invokeLater(RunnableQueue.java:277)
at org.apache.batik.swing.svg.AbstractJSVGComponent.updateRenderingTransform(AbstractJSVGComponent.java:1057)
at org.apache.batik.swing.gvt.AbstractJGVTComponent$1.componentResized(AbstractJGVTComponent.java:237)
at java.awt.AWTEventMulticaster.componentResized(Unknown Source)
at java.awt.Component.processComponentEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Thanks in advance, I have searched everywhere and tried a lot, but could not find a solution.
Edit:
This is the invokeLater-Method of Batik where the Exception is actually thrown:
public void invokeLater(Runnable r) {
if (runnableQueueThread == null) {
throw new IllegalStateException
("RunnableQueue not started or has exited");
}
synchronized (list) {
list.push(new Link(r));
list.notify();
}
}
runnableQueueThrad is set inside that class' run()-Method and set to null at the end.
So I guess I have to do some kind of synchronization.
Hazard a guess, the "public void run()" code should not be inside another method and really is a thread class/interface objects so called constructor(interface version actually).
Remove it to its own class(e.g. nested subclass to preserve scope) and implement the "thread runnable" interface on the class to place the "run()" method in it to use.
Stack trace says the run method is not available because it does not actually have such a method(or at least not properly declared) so it is in an "illegal state".