I wonder about a Java error that is repeatedly occurs in MATLAB. It typically occurs when MATLAB is doing some heavy stuff with Java. This can for example be holding Ctrl + Z or Ctrl + Y.
I did by mistake erase the error message before I copied it, but I think that I can pass the core of the problem anyway.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
...
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Why did this error occur? I have found some information about this from MATLAB r2007, this due to that Java Swing is thread unsafe and MATLAB lacked support to ensure thread safety. However, that is supposed to have been fixed in MATLAB r2008b. So why do I get it now?
Here is the full stack trace:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.netbeans.editor.BaseDocument.notifyUnmodify(BaseDocument.java:1465)
at org.netbeans.editor.BaseDocument.notifyModifyCheckEnd(BaseDocument.java:816)
at org.netbeans.editor.BaseDocumentEvent.redo(BaseDocumentEvent.java:336)
at javax.swing.undo.UndoManager.redoTo(Unknown Source)
at javax.swing.undo.UndoManager.redo(Unknown Source)
at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)
at org.netbeans.editor.ActionFactory$RedoAction.actionPerformed(ActionFactory.java:767)
at org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:259)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at com.mathworks.widgets.SyntaxTextPaneBase.processKeyEvent(SyntaxTextPaneBase.java:1187)
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.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(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)
Well, based on your stack trace, probably there isn’t any definitive answer to your question, as you have already seen in MATLAB's forum, but given this line, I think there's a possible explanation:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
...
at javax.swing.undo.UndoManager.redoTo(Unknown Source) // <-- here!
at javax.swing.undo.UndoManager.redo(Unknown Source)
at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)
...
UndoManager class keeps an internal collection of UndoableEdit objects. This collection is actually inherithed from its superclass: CompoundEdit.
The internal implementation of UndoManager#redo() and UndoManager#redoTo(UndoableEdit edit) looks like this:
public class UndoManager extends CompoundEdit implements UndoableEditListener {
...
public synchronized void redo() throws CannotRedoException {
if (inProgress) {
UndoableEdit edit = editToBeRedone();
if (edit == null) {
throw new CannotRedoException();
}
redoTo(edit);
} else {
super.redo();
}
}
...
protected void redoTo(UndoableEdit edit) throws CannotRedoException {
boolean done = false;
while (!done) {
UndoableEdit next = edits.elementAt(indexOfNextAdd++);
next.redo(); // NPE here?
done = next == edit;
}
}
...
}
Considering this implementation and given that Swing's Event Dispatch Thread (EDT) is prone to cause troubles, I think it's probably a threading issue between MATLAB threads and the EDT. Specifically speaking this MATLAB-invoked method could be the source of the problem:
at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)
Since you say MATLAB needs to do heavy work, it's not unreasonable to think this method is trying to redo some edit that might well not be available anymore or might not be available yet, due to synchronization problems with the EDT.
You can find the ~/.matlab folder which contains MATLAB settings, etc. Use ls -la to show all hidden files and folders.
Open a terminal and execute sudo chmod 757 -R ~/.matlab.
Similarly there is a folder, MATLAB, in Documents.
Execute sudo chmod 757 -R ~/Documents/MATLAB.
Now restart MATLAB without root privileges. It worked for me on Ubuntu 14.04 (Trusty Tahr) and MATLAB 2015a.
Related
BACKGROUND
I'm trying to build a map of earthquake events with data parsed from an RSS feed using the "Unfolding maps" library in Java (this is part of the Coursera course on OOP with Java). In theory, the data from the feed gets parsed into properties of the earthquake (location, magnitude, ...) which then form the basis for these marker objects that get displayed on a map. The libraries that are used are "Processing" and the "Unfolding Maps" library.
PROBLEM
Theres an "Unknown Source" error in the part, where I want to set the color property of the earthquake marker, depending on the magnitude of the event (ie. magnitude > 3 is "yellow").
Here's the error message:
Exception in thread "Animation Thread" java.lang.NullPointerException
at de.fhpotsdam.unfolding.marker.AbstractMarker.getProperty(Unknown Source)
at module3.EarthquakeCityMap.setup(EarthquakeCityMap.java:101)
at processing.core.PApplet.handleDraw(PApplet.java:2365)
at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:873)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:690)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:672)
at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1383)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1277)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1131)
at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1394)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(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$JavaSecurityAccessImpl.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)
And here is the code
for (Marker marker:markers) {
if ((int) (marker.getProperty("magnitude")) > 3) {
System.out.println("trying to set the colour to yellow");
//marker.setColor(yellow);
}
}
The line with "setColor(yellow)" is commented out, as it seems that this is a problem of its own (may or may not have to do with it).
Anybody have an idea where this may come from and what I could read up on to better understand the problem? I'm pretty new to programming so any advice on how to learn the process of tracing errors / finding out the cause of a problem would be fantastic.
I have a NullPointerException in my application, that happens only on one specific PC, and is reproducible. I wrote my GUI using Javafx with some Swing JPanels on it via SwingNode.
What should I do?
Exception-Time = 2016-08-30 06:55:50 UTC Exception-Tag = 0 Exception-Message = Thread AWT-EventQueue-0 (Id = 55) throw exception: null Stack-Trace = java.lang.NullPointerException
at sun.swing.JLightweightFrame.updateClientCursor(Unknown Source)
at sun.swing.JLightweightFrame.access$000(Unknown Source)
at sun.swing.JLightweightFrame$1.updateCursor(Unknown Source)
at sun.awt.windows.WLightweightFramePeer.updateCursorImmediately(Unknown Source)
at java.awt.Component.updateCursorImmediately(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(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$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.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$JavaSecurityAccessImpl.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)
More about the problem:
Apparently, this is a bug at the JDK itself (versions 8 and 9) and probably won't get fixed until JDK10.
This exception is thrown from within the sun.swing.JLightweightFrame.java class, at the updateClientCursor function (lines 472-749):
private void updateClientCursor() {
Point p = MouseInfo.getPointerInfo().getLocation();
SwingUtilities.convertPointFromScreen(p, this);
Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
if (target != null) {
content.setCursor(target.getCursor());
}
}
In general, this is happening because MouseInfo.getPointerInfo() can return NULL, for example, when you move between graphic devices. 'MouseInfo' can still hold the former graphic device information, then getPointerInfo() can return NULL if the mouse already moved to the new graphic device and MouseInfo still didn't updated to the new graphic device information. this scenario will cause a Null Pointer Exception on this line MouseInfo.getPointerInfo().getLocation() for trying to run a method of a NULL object.
For me, NPE is thrown when I move my JavaFX app window between monitors on my multiscreen machine. Its not happening every time but it is reproducible very easily.
I'm using a Swing component in a JavaFX SwingNode component.
This bug is already a known issue at Oracle bug list.
Code Fix:
This snippet shows an optional fix for this bug:
private void updateClientCursor() {
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
if (pointerInfo == null) {
/*
* This can happen when JavaFX cannot decide
* which graphics device contains the current
* mouse position.
*/
return;
}
Point p = pointerInfo.getLocation();
SwingUtilities.convertPointFromScreen(p, this);
Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
if (target != null) {
content.setCursor(target.getCursor());
}
}
Taken from JetBrains repository
Optional solution:
Since it is a bug withing the formal Oracle JDK, there is no much I can do about it. there are fixes applied in other non-formal JDKs like OpenJDK for example, which applied a fix, but I don't know which version will apply this fix yet.
For me, I would probably try to compile and use my own JDK with the applied fix and use it in my project, but this is a hard to maintain and not so flexible solution. If someone have another fix/workaround I would be happy to hear.
Googling a lot, I found nothing about the problem with this specific class (Key.Adapter.class), but there are a lot of topics about rt.jar of course, and I tried so many things to correct it, I tried to set the location of rt.jar and installed the plugin Java Source Attacher (didn't work). I reinstalled Eclipse as well, but the error still occurs:
What's strange about this is that I didn't make any change at anything related to the library (if I did, that was not intentional). I was just moving some things but nothing related to the libraries. The console returns NullPointerException at line 190:
name2.addKeyListener(new KeyAdapter() {
#Override
public void keyPressed(KeyEvent arg0) {
int key = arg0.getKeyCode();
if (key == KeyEvent.VK_ESCAPE) {
//Custom button text
Object[] options = {"Sim",
"Não"};
int choice = JOptionPane.showOptionDialog(frame1,
"Deseja sair do jogo?",
"Mensagem",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[1]);
if (choice == 0) {
System.exit(0);
}
}
}
}
);
To make a new project will be that way as well. And the Window Designer / Run doesn't work as well.
Is there another possibility to make rt.jar useful again?
java.lang.NullPointerException
at view.Main.<init>(Main.java:191)
at view.Main$1.run(Main.java:49)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(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.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)
Welcome, i am programming a simple RPG game in java applet. It is getting more and more complicated and many errors are thrown to my face. Today i have problem with .remove(); method.
Exception in thread "AWT-EventQueue-1" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
at java.util.ArrayList$Itr.remove(Unknown Source)
at rpg.main.paint(main.java:365)
at rpg.main.update(main.java:331)
at sun.awt.RepaintArea.updateComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(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)
That's how error log looks like. Code of program:
main.java
As we can see error appears in paint methid in the end of program, but i dont know maybe it is caused by wrong initiation in the beginning of program?
public void initLocatables()
public void initLocatables2()
And i have to admit that they are called in main while loop in run method.
These is place where error apears, and below in comment i have included previous method that has also thrown error, both in remove();
for (Iterator i = locatablesArray.listIterator(); i.hasNext();) {
Locatable l = (Locatable) i.next();
l.draw(g);
i.remove();
}
/*while(itrLocatables.hasNext())
{
Locatable l = itrLocatables.next();
l.draw(g);
l.remove();
}*/
Thank you for any reply.
Maybe when you call repaint() in run(), paint() is queued to EDT and called as soon as possible; while iterating locatablesArray a call to initLocatables2() in run() is done another time and the re-init of locatablesArray in the same time the code of paint() will produce the error.
My advice is to separate init operation in a specific init section and call it once, the run your main loop.
Just another thing: why are you init a Iterator (class field itrLocatables) in initLocatables2()? Use iterator when needed if possible.
Hope to be clear, English is not my native language.
You cannot remove objects from a list/map while you are iterating them. That's the cause of the ConcurrentModificationException
i.remove();
If you will draw all the Locatable elements, and then clear the collection, maybe you should draw them all first, and then clear the collection, instead of removing them on the fly.
for (Iterator i = locatablesArray.listIterator(); i.hasNext();) {
Locatable l = (Locatable) i.next();
l.draw(g);
}
// Clear everything from the list
locatablesArray.clear();
java.util.ConcurrentModificationException
Another approach is to use a for loop through the locatablesArray starting at the end vs the beginning. That way any elements that are removed won't change the location of elements of the array that are yet to be scanned.
I am facing a NullPointerException and I can't figure out where or why it occurs. I'm using JavaFX for a project, and it contains a .fxml file which has lots of components (mostly SVGPaths, Circle objects and Text objects). They are imported into a Controller class. Each SVGPath has a mouse listener (for click, enter and exit actions) and sometimes I get a NullPointerException that makes me crazy because I have spent hours trying to solve it. Here is the exact stack trace of exception.
java.lang.NullPointerException
at com.sun.javafx.sg.prism.NGTextHelper.computeBoundsLogical(Unknown Source)
at com.sun.javafx.sg.prism.NGTextHelper.computeContentBounds(Unknown Source)
at javafx.scene.text.Text.impl_computeGeomBounds(Unknown Source)
at javafx.scene.Node.updateGeomBounds(Unknown Source)
at javafx.scene.Node.getGeomBounds(Unknown Source)
at javafx.scene.Node.getLocalBounds(Unknown Source)
at javafx.scene.Node$MiscProperties$2.computeBounds(Unknown Source)
at javafx.scene.Node$LazyBoundsProperty.get(Unknown Source)
at javafx.scene.Node$LazyBoundsProperty.get(Unknown Source)
at javafx.scene.Node.getBoundsInLocal(Unknown Source)
at com.sun.javafx.scene.control.skin.TextAreaSkin$ContentView.layoutChildren(Unknown Source)
at javafx.scene.Parent.layout(Unknown Source)
at javafx.scene.Parent.layout(Unknown Source)
at javafx.scene.Parent.layout(Unknown Source)
at javafx.scene.Scene.layoutDirtyRoots(Unknown Source)
at javafx.scene.Scene.doLayoutPass(Unknown Source)
at javafx.scene.Scene.access$3900(Unknown Source)
at javafx.scene.Scene$ScenePulseListener.pulse(Unknown Source)
at com.sun.javafx.tk.Toolkit.firePulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$3$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:722)
I will appreciate it a lot if someone can help and also explain the reason of this occurrence.
Probably you already solved this, but maybe my solution will help others.
If you are working with JavaFX in a Swing Application you have to be careful to only execute JavaFX code in the correspondent thread and to run Swing code only in the EDT.
I was having a similar problem in my application and it was due to the execution of JavaFX code in the EDT. So, to correct this, I reviewed the code to ensure the use of Platform.runLater(...) on methods that were possibly called from the EDT.
Platform.runLater(new Runnable() {
#Override
public void run() {
// JavaFX manipulation code.
}
}
This seems easy but can be tricky to remember sometimes. So, to be sure, review your JavaFX code searching for public methods and interfaces that can be invoked by Swing components and events.