java.lang.IllegalArgumentException: im == null! error - java

I just learned how to use threads yesterday and I'm trying to encode some images using threads but I'll get this error
java.lang.IllegalArgumentException: im == null!
I tried doing this exact same thing without threads and it worked fine just kind of slowly, not because of the image io but because of the time it takes to encode images.
the WinDef.HDC is a variable type I got from the JNA library. When I did try it without threads I could easily write out 1000 images (about 60mb).
//The thread class
public class imageEncoderThread extends Thread {
HDC originalImage;
BufferedImage image;
public imageProcessThread (HDC rI) {
originalImage = rI'
}
#Override
public void run() {
//returns a buffered image
image = process(rawImage);
try {
ImageIO.write(image, "jpg", new File (filePath));
} catch (IOException e) {
}
}
}
//full stack trace
Exception in thread "Thread-5" java.lang.IllegalArgumentException: im == null!
at javax.imageio.ImageIO.write(Unknown Source)
at javax.imageio.ImageIO.write(Unknown Source)
at com.capture.SingleImageEncoderThread.run(Thread.java:33)
Exception in thread "Thread-7" java.lang.IllegalArgumentException: im == null!
at javax.imageio.ImageIO.write(Unknown Source)
at javax.imageio.ImageIO.write(Unknown Source)
at com.capture.SingleImageEncoderThread.run(Thread.java:33)
Exception in thread "Thread-6" java.lang.IllegalArgumentException: im == null!
at javax.imageio.ImageIO.write(Unknown Source)
at javax.imageio.ImageIO.write(Unknown Source)
//and so on with the same exception

It's almost certainly the case that you cannot call:
image = JNAScreenShot.encodeRawWindow(rawImage, bounds);
from any thread other than the main ui thread. See:
http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/6398cda5-5393-4b16-b8dc-5bbf8902033f/ (specifically, I do not think HDCs are usable outside the main ui thread).
So, you'll need to create the screenshot first, then pass it to your thread to do the IO (that's probably the slow part, anyway).

Related

java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4

I'm trying to set the string of a Text object from a Thread but it's giving me this error:
Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(Unknown Source)
at javafx.scene.Scene.addToDirtyList(Unknown Source)
at javafx.scene.Node.addToSceneDirtyList(Unknown Source)
at javafx.scene.Node.impl_markDirty(Unknown Source)
at javafx.scene.shape.Shape.impl_markDirty(Unknown Source)
at javafx.scene.Node.impl_geomChanged(Unknown Source)
at javafx.scene.text.Text.impl_geomChanged(Unknown Source)
at javafx.scene.text.Text.needsTextLayout(Unknown Source)
at javafx.scene.text.Text.needsFullTextLayout(Unknown Source)
at javafx.scene.text.Text.access$200(Unknown Source)
at javafx.scene.text.Text$2.invalidated(Unknown Source)
at javafx.beans.property.StringPropertyBase.markInvalid(Unknown Source)
at javafx.beans.property.StringPropertyBase.set(Unknown Source)
at javafx.beans.property.StringPropertyBase.set(Unknown Source)
at javafx.scene.text.Text.setText(Unknown Source)
at uy.com.vincent.fx.handling.TableController$1.run(TableController.java:70)
Handler Class:
#FXML
private Text timer;
#Override
public void initialize(URL url, ResourceBundle rb) {
init();
new Thread() {
public void run() {
while(true) {
Calendar cal = new GregorianCalendar();
int hour = cal.get(cal.HOUR);
int minute = cal.get(cal.MINUTE);
int second = cal.get(cal.SECOND);
int AM_PM = cal.get(cal.AM_PM);
String time = hour + "" + minute + "" + second;
timer.setText(time);
}
}
}.start();
}
I'm following a tutorial.
The guy in the tutorial is not using JavaFX.
I have tried using Platform.runLater(), it does work but it crashes my program.
I also tried creating a Timer on the Platform.runLater(new Runnable() { }) method but it gives me the same error as before.
Wrap timer.setText() in Platform.runLater(). Outside it, inside the while loop, add Thread.sleep(1000);
The reason behind Illegal State Exception is you are trying to update UI on some thread other than JavaFX Application thread.
The reason why your app was crashing when you added it was you were overloading the UI thread by adding a process to be executed on the UI thread infinitely. Making the thread sleep for 1000ms will help you overcome the issue.
If possible replace while(true) with a Timer or TimerTask.
For more options follow this link

Java - Client giving error on connect

I am working on a simple Java messaging program. Before I begin working on more complex features, I would like to get the basic system working. Currently
Multiple clients can connect
Multiple clients can send messages that the server receives
Server closes connections when the client is terminates
This code in particular appears to be what is giving the errors. It is the run() method in my ClientThread.java thread (that implements runnable). This thread is for handling incoming messages from the server (sending messages works fine).
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class ClientThread implements Runnable{
private Socket server;
private DataInputStream in;
private DataOutputStream out;
public Text msgContent;
public void login(Stage stage, Scene main, String username, String password, String portString, String host) {
try {
int port = Integer.parseInt(portString);
this.server = new Socket(host, port);
this.in = new DataInputStream(server.getInputStream());
this.out = new DataOutputStream(server.getOutputStream());
stage.setScene(main);
Platform.runLater(new ClientThread());
}
catch (NumberFormatException e) {
System.out.println("Invalid Port");
return;
}
catch (IOException e) {
System.out.println("Error Connecting to Server");
return;
}
}
public void run() {
String msg = "";
try {
while (true) {
msg = in.readUTF(); //This line gives Errors
System.out.println("Read message from server");
msgContent.setText(msgContent.getText() + msg + "\n");
System.out.println("Added message from server to view");
}
}
catch(Exception ioe) {
ioe.printStackTrace();
System.out.println("Failed to read message from server and add to view.");
}
}
public void sendMsg(String msg) {
try {
out.writeUTF(msg);
} catch (Exception ioe) {
ioe.printStackTrace();
}
}
}
Note that msgContent is a Text object in my JavaFX frontend and in the inputStream from the server. My full code is here. The error I am getting is
java.lang.NullPointerException
at ClientThread.run(ClientThread.java:42)
at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.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.access$300(Unknown Source)
at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Failed to read message from server and add to view.
Also note that I am using Platform.runLater() to run this method. I want to know how to fix the above error so my code works. Thanks in advance.
Cause of NullPointer Exception
in is null.
Your NullPointerException occurs because in this call you create a new instance of the ClientManager class: Platform.runLater(new ClientThread());, so it won't use existing instance of ClientManager in which you have initialized the in and out members. Instead, you could use Platform.runLater(this);, to get rid of your NullPointerException.
However, your code has other issues...
Incorrect concurrent programming
You are hanging the JavaFX application thread which will stop your application from rendering or responding to UI input. Never busy wait the JavaFX application thread.
One way to accomplish what you are trying to do is to use the JavaFX concurrency utilities, in particular a Task.
Run the task on it's own thread, then it can loop, accepting input forever and it won't block your UI thread. You can (perhaps) make your thread a non-daemon thread so that it exits automatically when all of the other daemon threads complete. You could feed the input back to your UI using Platform.runLater. But, for the simple example you provided where you want to update some message text, instead you can invoke updateMessage (note this does not need a Platform.runLater call as the Task class takes care of that kind of detail for you). To get your message label updated, you can bind it's text property to the task's message property. There are examples of how to do this in the Task javadoc.

java.lang.InterruptedException using swingworker

I am using Swingworker to request value from url address to dynamically change a version of displayed information. At certain cases this worker is cancelled. The problem is that I get java.lang.InterruptedException sometimes (but not every time I cancel worker). I am not sure what to do with it, moreover I have no idea where it is thrown, I cannot debug it because I get it when I do lots of version changes in short time (I use slider and this happens when I am dragging it for some time) . Everything works fine but I get this annoying error:
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at sun.plugin2.message.Queue.waitForMessage(Unknown Source)
at sun.plugin2.message.Pipe$2.run(Unknown Source)
at com.sun.deploy.util.Waiter$1.wait(Unknown Source)
at com.sun.deploy.util.Waiter.runAndWait(Unknown Source)
at sun.plugin2.message.Pipe.receive(Unknown Source)
at sun.plugin2.main.client.MessagePassingExecutionContext.doCookieOp(Unknown Source)
at sun.plugin2.main.client.MessagePassingExecutionContext.getCookie(Unknown Source)
at sun.plugin2.main.client.PluginCookieSelector.getCookieFromBrowser(Unknown Source)
at com.sun.deploy.net.cookie.DeployCookieSelector.getCookieInfo(Unknown Source)
at com.sun.deploy.net.cookie.DeployCookieSelector.get(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.setCookieHeader(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.writeRequests(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.dbwiki.web.applet.ValueRequester.doInBackground(ValueRequester.java:40)
at org.dbwiki.web.applet.ValueRequester.doInBackground(ValueRequester.java:1)
at javax.swing.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at javax.swing.SwingWorker.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)
Also after each exception which is showed above additional message is thrown:
sun.plugin2.main.client.PluginMain: unrecognized message ID 46
Interesting thing that exception is only being thrown when program is run in the browser as an applet, if program is run as applet from api no exceptions are thrown.
My StringWorker:
package org.dbwiki.web.applet;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import javax.swing.SwingWorker;
public class ValueRequester extends SwingWorker<Void, Void> {
HtmlGenerator htmlGen;
ArrayList<String[]> versionsData;
String id;
private String dbName;
ValueRequester (HtmlGenerator htmlGen, ArrayList<String[]> versionData, int ver){
try {
this.htmlGen=htmlGen;
if (TreeVisualiser.typeParameter.equals(TreeVisualiser.StructureVisualiserParameter))
this.id=htmlGen.getElem().getVersionElementId(ver);
else if(TreeVisualiser.typeParameter.equals(TreeVisualiser.HistoryVisualiserParameter))
this.id=htmlGen.getElem().getId();
this.dbName=htmlGen.getElem().getDBName();
this.versionsData=versionData;
} catch (Exception e) {
e.printStackTrace();
}
}
protected Void doInBackground() throws Exception {
try{
String value="";
URL historyURL = new URL("http://127.0.0.1:8080/"+dbName+id+"?value");
URLConnection hc = historyURL.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(hc.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
value+=line;
}
in.close();
this.htmlGen.formDisplayerHead();
this.htmlGen.formNodeDataHtml(value,this.versionsData);
this.htmlGen.formDisplayerTail();
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
protected void done()
{
if (!this.isCancelled())
this.htmlGen.dataDisplayer.setText(this.htmlGen.getHtml());
}
}
I have now idea what causes it, how to handle it or at least how to hide it (as everything works normal). Any help would be appreciated.
UPDATE:
I try to catch this exception in the ValueRequester.doInBackround(), however my catch statement don't catch the exception. My updated code of doInBackground():
protected Void doInBackground() throws Exception {
try{
String value="";
URL historyURL = new URL("http://127.0.0.1:8080/"+dbName+id+"?value");
URLConnection hc = historyURL.openConnection();
InputStream inputStrm=hc.getInputStream();
InputStreamReader inputStrmRdr= new InputStreamReader(inputStrm);
this.in = new BufferedReader(inputStrmRdr);
String line;
while ((line = in.readLine()) != null) {
value+=line;
}
this.htmlGen.formDisplayerHead();
this.htmlGen.formNodeDataHtml(value,this.versionsData);
this.htmlGen.formDisplayerTail();
}catch (InterruptedException e){
System.out.println("Interrupted Exception caught!");
// e.printStackTrace();
}
return null;
}
Unfortunately stack trace is still printed instead of my system out message. Any idea what could be wrong here?
As far as I know, an InterruptedException only occurs if some other thread calls Thread.interrupt() on a thread that is blocked. In this case, it is clear that the interrupted thread was in a wait() call at the time.
Looking at the SwingWorker code, it appears that the worker thread will get an interrupt if the thread that scheduled decides to call cancel(true) on it. Depending on what the worker thread is doing at the time, it may get an InterruptedException, or it may just have its Thread.interrupted flag set.
So the solution to your problem would appear to be to find out what is calling cancel(true) on the SwingWorker instance. Then either change it to not do that ... or make your worker class deal with the InterruptedException appropriately. The appropriate behaviour would probably be to catch the exception and quietly return from call(...)
To me it just looks like you are calling worker.cancel(true); (assuming worker is your SwingWorker). The true indicates that if the current Thread is in an interruptible state, the Thread can be interrupted. When this happens, it automatically throws an Exception indicating that the Thread has been interrupted allowing you to release resources and possibly do something. I guess in your case you can safely ignore this and simply close the opened streams.
In your case, depending on how far you are in your "Work", the task may get interrupted or not.
See more information on Thread interruption here.

What caused the java.lang.InternalError (it extends VirtualMachineError)

When I tried to do SVN synchronize I got this error. I wonder why it has happen, any ideas? It works great after restarting eclipse, but I wonder what could cause it and how its possible that the jar was not found.
!ENTRY org.eclipse.team.svn.core.svnnature 4 0 2011-12-09 14:22:15.534
!MESSAGE SVN: '0x00000107: Synchronizing' operation finished with error
!SUBENTRY 1 org.eclipse.team.svn.core.svnnature 4 0 2011-12-09 14:22:15.534
!MESSAGE Synchronize operation failed.
!STACK 0
java.lang.InternalError
at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:755)
at sun.misc.URLClassPath.getResource(URLClassPath.java:169)
at sun.misc.URLClassPath.getResource(URLClassPath.java:221)
at java.lang.ClassLoader.getBootstrapResource(ClassLoader.java:1151)
at java.lang.ClassLoader.getResource(ClassLoader.java:1000)
at java.lang.ClassLoader.getResource(ClassLoader.java:998)
at java.lang.ClassLoader.getSystemResource(ClassLoader.java:1101)
at javax.crypto.SunJCE_b.i(DashoA13*..)
at javax.crypto.SunJCE_b.g(DashoA13*..)
at javax.crypto.SunJCE_b$1.run(DashoA13*..)
at java.security.AccessController.doPrivileged(Native Method)
at javax.crypto.SunJCE_b.<clinit>(DashoA13*..)
at javax.crypto.KeyAgreement.getInstance(DashoA13*..)
at com.sun.net.ssl.internal.ssl.JsseJce.getKeyAgreement(JsseJce.java:241)
at com.sun.net.ssl.internal.ssl.JsseJce.isEcAvailable(JsseJce.java:158)
at com.sun.net.ssl.internal.ssl.CipherSuite$KeyExchange.isAvailable(CipherSuite.java:271)
at com.sun.net.ssl.internal.ssl.CipherSuite.isAvailable(CipherSuite.java:143)
at com.sun.net.ssl.internal.ssl.CipherSuiteList.buildAvailableCache(CipherSuiteList.java:210)
at com.sun.net.ssl.internal.ssl.CipherSuiteList.getDefault(CipherSuiteList.java:233)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.init(SSLSocketImpl.java:508)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:451)
at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:56)
at org.tmatesoft.svn.core.internal.util.SVNSocketFactory.createSSLSocket(SVNSocketFactory.java:73)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.connect(HTTPConnection.java:186)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:327)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:275)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:263)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.exchangeCapabilities(DAVConnection.java:516)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.open(DAVConnection.java:98)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.openConnection(DAVRepository.java:999)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.getRepositoryUUID(DAVRepository.java:146)
at org.tmatesoft.svn.core.wc.SVNBasicClient.createRepository(SVNBasicClient.java:342)
at org.tmatesoft.svn.core.wc.SVNBasicClient.createRepository(SVNBasicClient.java:330)
at org.tmatesoft.svn.core.wc.SVNStatusClient.doStatus(SVNStatusClient.java:338)
at org.tmatesoft.svn.core.javahl.SVNClientImpl.status(SVNClientImpl.java:300)
at org.tmatesoft.svn.core.javahl.SVNClientImpl.status(SVNClientImpl.java:282)
at org.polarion.team.svn.connector.svnkit.SVNKitConnector.status(SVNKitConnector.java:341)
at org.eclipse.team.svn.core.extension.factory.ThreadNameModifier.status(ThreadNameModifier.java:608)
at org.eclipse.team.svn.core.operation.local.RemoteStatusOperation$2.run(RemoteStatusOperation.java:147)
at org.eclipse.team.svn.core.utility.ProgressMonitorUtility.doSubTask(ProgressMonitorUtility.java:118)
at org.eclipse.team.svn.core.operation.AbstractActionOperation.protectStep(AbstractActionOperation.java:154)
at org.eclipse.team.svn.core.operation.AbstractActionOperation.protectStep(AbstractActionOperation.java:149)
at org.eclipse.team.svn.core.operation.local.RemoteStatusOperation.runImpl(RemoteStatusOperation.java:145)
at org.eclipse.team.svn.core.operation.AbstractActionOperation.run(AbstractActionOperation.java:81)
at org.eclipse.team.svn.core.utility.ProgressMonitorUtility.doTask(ProgressMonitorUtility.java:104)
at org.eclipse.team.svn.core.operation.CompositeOperation.runImpl(CompositeOperation.java:95)
at org.eclipse.team.svn.core.operation.AbstractActionOperation.run(AbstractActionOperation.java:81)
at org.eclipse.team.svn.core.operation.LoggedOperation.run(LoggedOperation.java:39)
at org.eclipse.team.svn.core.utility.ProgressMonitorUtility.doTask(ProgressMonitorUtility.java:104)
at org.eclipse.team.svn.core.utility.ProgressMonitorUtility.doTaskExternal(ProgressMonitorUtility.java:90)
at org.eclipse.team.svn.core.synchronize.AbstractSVNSubscriber.findChanges(AbstractSVNSubscriber.java:314)
at org.eclipse.team.svn.core.synchronize.AbstractSVNSubscriber$UpdateStatusOperation$2.run(AbstractSVNSubscriber.java:349)
at org.eclipse.team.svn.core.utility.ProgressMonitorUtility.doSubTask(ProgressMonitorUtility.java:118)
at org.eclipse.team.svn.core.operation.AbstractActionOperation.protectStep(AbstractActionOperation.java:154)
at org.eclipse.team.svn.core.operation.AbstractActionOperation.protectStep(AbstractActionOperation.java:149)
at org.eclipse.team.svn.core.synchronize.AbstractSVNSubscriber$UpdateStatusOperation.runImpl(AbstractSVNSubscriber.java:347)
at org.eclipse.team.svn.core.operation.AbstractActionOperation.run(AbstractActionOperation.java:81)
at org.eclipse.team.svn.core.operation.LoggedOperation.run(LoggedOperation.java:39)
at org.eclipse.team.svn.core.utility.ProgressMonitorUtility.doTask(ProgressMonitorUtility.java:104)
at org.eclipse.team.svn.core.utility.ProgressMonitorUtility.doTaskExternal(ProgressMonitorUtility.java:90)
at org.eclipse.team.svn.core.utility.ProgressMonitorUtility.doTaskExternal(ProgressMonitorUtility.java:81)
at org.eclipse.team.svn.core.synchronize.AbstractSVNSubscriber.refresh(AbstractSVNSubscriber.java:186)
at org.eclipse.team.svn.core.synchronize.UpdateSubscriber.refresh(UpdateSubscriber.java:73)
at org.eclipse.team.core.subscribers.Subscriber.refresh(Subscriber.java:466)
at org.eclipse.team.core.subscribers.SubscriberMergeContext.refresh(SubscriberMergeContext.java:85)
at org.eclipse.team.core.mapping.provider.SynchronizationContext.refresh(SynchronizationContext.java:109)
at org.eclipse.team.internal.ui.synchronize.RefreshModelParticipantJob.doRefresh(RefreshModelParticipantJob.java:69)
at org.eclipse.team.internal.ui.synchronize.RefreshParticipantJob.run(RefreshParticipantJob.java:309)
at org.eclipse.team.internal.ui.synchronize.RefreshModelParticipantJob.run(RefreshModelParticipantJob.java:117)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: java.io.FileNotFoundException: /usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/jce.jar
at sun.misc.URLClassPath$JarLoader.getJarFile(URLClassPath.java:644)
at sun.misc.URLClassPath$JarLoader.access$600(URLClassPath.java:540)
at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:607)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:599)
at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:753)
... 69 more
no, it always works. just one time it did not.
Looking at the JDK source code of sun.misc.URLClassPath and sun.misc.FileURLMapper, there is code in FileURLMapper.exists() that does the following:
public boolean exists() {
String path = getPath();
File f = new File (path);
return f.exists();
}
Assuming nothing crazy has happened like the jce.jar file was actually deleted (such as through upgrading version of Java while Eclipse is running), the File.exists() call might fail because of some other reason (out of memory / file descriptors possibly? On Unix file.exists() eventually calls the stat/stat64 function)
Drilling down to the code found here the things I can see: Invocation of sun.misc.URLClassPath.JarLoader.ensureOpen() at line 753 leads to InternalError raised at line 755.
The method is like as below:
private void ensureOpen() throws IOException {
if (jar == null) {
try {
java.security.AccessController.doPrivileged(new java.security.PrivilegedExceptionAction() {
public Object run() throws IOException {
....
}
});
} catch (java.security.PrivilegedActionException pae) {
throw (IOException) pae.getException(); // this exception is thrown
}
}
}
Here java.security.AccessController.doPrivileged(PrivilegedExceptionAction<T>) is a native method. Documentation is here.
As it can be understood from document, that error is thrown possibly for chekced exception that occur while processing public Object run() throws IOException {.
Check this file
/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/jce.jar
probably your eclipse tries to authenticate with repository but lacks classes needed to process and perform auth.

Why am I getting a nullPointerException when Clojure code calls a JPanel function?

I am having trouble determining why my code gets a nullPointer exception. I'm trying to write a swing application using a combination of Java and Clojure. I have a Clojure function that calls a function in my JPanel subclass, and I'm getting a lot of exceptions that are driving me crazy.
I've simplified my code as much as possible, and I'm still getting these errors.
(defn draw-state
"Draws the current state."
[state display]
(do-swing (.drawBlocks display)))
Here's the entire JPanel subclass, although I think the only relevant part is the drawBlocks function (which eventually will be replacing the blocks array):
public class TDisplay extends JPanel {
private Block[] blocks = new Block[1];
/**
* Create the panel.
*/
public TDisplay() {
setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
setBackground(Color.WHITE);
setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
blocks[0] = new Block(3, 4, 0);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (Block b : blocks) {
if (b == null) continue;
switch (b.colour) {
case 0:
g.setColor(Color.WHITE);
break;
case 1:
g.setColor(Color.BLACK);
break;
}
g.fillRect(b.x * Block.SIZE, b.y * Block.SIZE, Block.SIZE, Block.SIZE);
}
}
public void drawBlocks() {
System.out.println("Hello world");
}
}
And the stack trace:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: java.lang.NullPointerException
at clojure.lang.AFn.run(AFn.java:28)
at java.awt.event.InvocationEvent.dispatch(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)
Caused by: java.lang.NullPointerException
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:263)
at core$draw_state$fn__401.invoke(core.clj:43)
at clojure.lang.AFn.run(AFn.java:24)
... 8 more
I have the feeling that I'm missing something really obvious, and I'd appreciate any help.
Thanks!
How about the code that invokes draw-state -- is it possible that's passing in nulls for display?

Categories