Introduction
I am learning Java and JavaFX and in order to do that I am working on a little project which objective is to behave as password generator.
Basically, I have 2 windows, the first one allows the user to chose what kind of password he wants. Once he is done with that, the password is generated and it should be displayed on the second window.
What is particular here is that I decided to try out the procedural and declarative for coding the windows. Which means that the windows generating the password is coded in a java file. A contrario, the window that displays the password is declared in a FXML file.
What I struggle to do is to pass the generated password to the second window. I tried many things (bad things like using static methods) and I thought about trying to use bindings (that I only recently discovered).
But this last option didn't help either as I still get the same error all the time : a null pointer exception. It is coming from the line where the password is generated by the model and the obtained String is bound to a value in the controller of the seconde view.
I am kind of stuck here and I am thinking that mixing up 2 different ways to code my views isn't the best method. Still, maybe am I not doing the binding correctly, that's what I think and hope the most.
The code
So the controller of my first view looks like this (generating the password) :
public class GeneratePasswordController implements EventHandler<MouseEvent>{
#FXML private displayPasswordController displayPasswordController;
#Override
public void handle(MouseEvent event) {
//Doing some stuff that works, then generating the password and null pointer exception occurs here
//The method getNewPassword() returns a String (the password).
//The model is accessed statically (an instance has been created in the Application file (Main.java)).
displayPasswordController.pwdValueProperty().bind(Bindings.createStringBinding(()
-> Main.myModel.getNewPassword()));
}
}
And the controller of the view that displays the password :
public class NewPswdController {
#FXML private TextField displayPassword;
private final StringProperty pwdValue = new SimpleStringProperty("Password");
public StringProperty pwdValueProperty() {
return pwdValue;
}
public String getPwdValue() {
return pwdValue.get();
}
public void setPwdValue(String value) {
this.pwdValue.set(value);
}
#FXML
void initialize() {
dispPassword.textProperty().bind(Bindings.format("%s", pwdValue));
}
}
The null pointer exception appears at the specific line in the controller of the view that generates the password where the model actually generates it.
I am giving it, I guess it should help the most, but I couldn't really use that information untill now:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at s03.GeneratePasswordController.handle(GeneratePasswordController.java:61)
at s03.GeneratePasswordController.handle(GeneratePasswordController.java:1)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$271/1952832519.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(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/1232367853.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Thank you for looking into it. I might learn something new there I guess, but it seems that I can't find it out by myself and it is driving me nuts since a couple of days now.
If it appears that more information is needed, I can provide more. I included everything I think is necessary.
The trouble was coming from the controller that displays the password. The null pointer was most likely coming from the fact that there was no instance of that controller.
What is wrong is the part where I include the controller that displays the password using the #FXML annotation.
The following code, in the controller that generates the password, works just fine :
try {
//Load the view and controller
FXMLLoader loader = new FXMLLoader(getClass().getResource("displayPassword.fxml"));
Parent displayPassword = (Parent)loader.load();
Scene displayPasswordScene = new Scene(displayPassword);
displayPasswordController controller = loader.getController();
//Generate the password and set it
controller.setPwdValue(Pastis.model.getNewPassword());
//Load the new view on the stage
Main.getStage().setScene(displayPasswordScene);
Main.getStage().show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I found the answer on this question : FXMLLoader getController returns NULL?.
Related
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.
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.
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.
I have a question/problem related to Java Applet security...
I use the Applet that has to take files from server (ASP.NET) and represent the information from it. Applet take files using the code:
URL u = new URL(getCodeBase(), filename);
BufferedReader d = new BufferedReader(new InputStreamReader(u.openStream()));
This code appears in two places:
Init() method
Some another method Test() that called manually from JavaScript
So, when I try to load the page with Applet using the URL http://127.0.0.1:8000/Test.aspx, everything works fine and I can read file content from both methods. But if I change the URL on http://localhost:8000/, only the first method works properly and I can get files content and for the second one I get the next error message in JavaConsole:
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:8000 connect,resolve)
What it the difference in this case? Why 'localhost' is impossible in this case? Is there any way how to grant access to 'localhost' the same as 127.0.0.1?
here is simplest applet's example:
public class TestApplet extends Applet {
public void init()
{
System.out.println( "init...");
readDocument();
}
public void readDocument()
{
System.out.println( "read test.txt file...");
URL base = getCodeBase();
String filename = "test.txt";
try {
URL u = new URL(base, filename);
BufferedReader d = new BufferedReader(new InputStreamReader(u.openStream()));
System.out.println(d.readLine());
System.out.println("Done!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
and next code used on the client side:
<applet archive="/Content/test.jar" code="test.TestApplet.class" name="testApplet" mayscript></applet>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
var testApplet = document.testApplet;
testApplet.readDocument();
});
</script>
this code works perfectly when I try to use http://127.0.0.1:8000/Test.aspx
and doesn't work when I user http://localhost:8000/Test.aspx. I java console I see the next:
init...
read test.txt file...
some text...
Done!
read test.txt file...
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:8000 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at test.TestApplet.readDocument(TestApplet.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 sun.plugin.javascript.JSInvoke.invoke(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.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass$MethodInfo.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass.invoke0(Unknown Source)
at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$DefaultInvocationDelegate.invoke(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
P.S.: Applet is signed.
The problem is the call from JavaScript. If you are using JavaScript to call your method, the permissions of the call get down to the intersection of the JavaScript bridge's permissions (i.e. nothing) and the permissions of your own code - even if your own code is signed.
To avoid this, and use the full privileges of your applet's code, put the security-relevant parts inside a AccessController.doPrivileged(...) call. (Of course, your applet should first check that this can't do anything malicious.)
I have no idea why it works if you are using the IP address directly instead of localhost, though.
localhost is an alias for 127.0.0.1 so you may have to set/fix it in your enviroment. Under Windows you have to edit the file C:\Windows\System32\drivers\etc\hosts.
localhost is typically resolved to both ::1 and 127.0.0.1 and the OS/libc is usually set up so that IPv6 is preferred in these circumstances.
Therefore, it's likely you're allowing only 127.0.0.1 and not IPv6 connections from ::1.
I am trying to call an sighned applet on by GWT button click. I tried going through the gwtai method of creating an interface on client side then writing an Applet which implements the interface.Howevere I get a TargetInvokationException when I call the method on my onClick() event.
Here is the code I wrote :
screenCap.addListener(new ButtonListenerAdapter() {
public void onClick(Button button, EventObject e) {
String filePath = counterApplet.captureScreenShot(); (Throws exception here)
TextField filePathT = new TextField();
My Applet Interface :
import com.google.gwt.gwtai.applet.client.*;
#ImplementingClass(com.jpmorgan.rd.querymanager.applet.imageCaptureAppletImpl.class)
#Height("10")
#Width("10")
#Archive("GwtAI-Client.jar,GwtAI-Demo.jar")
public interface imageCaptureApplet extends Applet {
String captureScreenShot();
}
My applet implementation class :
import java.awt.*;
import javax.swing.JApplet;
public class imageCaptureAppletImpl extends JApplet implements imageCaptureApplet{
private static final long serialVersionUID = -511774647966368672L;
public String captureScreenShot() {
String file;
// do something
return file;
}
And the full stack trace:
load: class com.amol.test.imageCaptureAppletImpl.class not found.
java.lang.ClassNotFoundException: com.jpmorgan.rd.querymanager.server.imageCaptureAppletImpl.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://127.0.0.1:8888/com/amol/test/imageCaptureAppletImpl/class.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 9 more
Exception: java.lang.ClassNotFoundException: com.amol.test.imageCaptureAppletImpl.class
Any help around this is Appreciated.
I have also created a signed jar of my applet can you please suggest if there is a better way of calling this captureScreenShot() method from my GWT page on button click and getting a result back.
Also is JSNI a better way of doing this. If so can you show a example where a applet which passes a value back is called.
Many thanks in advanced.
PS: I used this page for the basis of my code on gwtai :
http://code.google.com/p/gwtai/wiki/GettingStarted
Thanks,
Amol
GwtAI is using JSNI to communicate with the applet. So whether you are writing the JSNI code yourself or using this library will be the same. Can you post the full stacktrace of your error?