Preview Applet Issue - NullPointerException

Screenshots, Vectorial Preview and printable exports
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Fujayel
Posts:6
Joined:01 Nov 2011 16:01
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Preview Applet Issue - NullPointerException

Post by Fujayel » 14 Apr 2012 18:56

Hi,

I am trying to use the Preview Applet in my application, however, I seem to have come across a peculiar issue.
For some reason, the application returns a NullPointerException out of the blue. It generally seems to work for the most part, but ocassionally it crashes and returns a NullPointerException. The main part of the error message is shown below:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.java2d.pipe.LoopPipe.draw(Unknown Source)
at sun.java2d.pipe.PixelToParallelogramConverter.draw(Unknown Source)
at sun.java2d.SunGraphics2D.draw(Unknown Source)
at processing.core.PGraphicsJava2D.drawShape(Unknown Source)
at processing.core.PGraphicsJava2D.ellipseImpl(Unknown Source)
at processing.core.PGraphics.ellipse(Unknown Source)
at org.gephi.preview.plugin.renderers.NodeRenderer.renderProcessing(NodeRenderer.java:114)
at org.gephi.preview.plugin.renderers.NodeRenderer.render(NodeRenderer.java:81)
at org.gephi.preview.PreviewControllerImpl.render(PreviewControllerImpl.java:258)
at org.gephi.preview.PreviewControllerImpl.render(PreviewControllerImpl.java:222)
The code I am using is as follows:

Code: Select all

//New Processing target, get the PApplet
ProcessingTarget target = (ProcessingTarget) previewController.getRenderTarget(RenderTarget.PROCESSING_TARGET);
PApplet applet = target.getApplet();
applet.init();
 
//Refresh the preview and reset the zoom
previewController.render(target);
target.refresh();
target.resetZoom();
The line that it is complaining about in my code is:

Code: Select all

previewController.render(target);
The applet seems to work fine without this line, although the visualisation is very small. What I wanted to ask is: what does this line of code actually do and is it needed?

Many thanks

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Preview Applet Issue - NullPointerException

Post by mbastian » 16 Apr 2012 03:27

what does this line of code actually do and is it needed?
This line is essential as this will execute the rendering (i.e. draw stuff) on the processing canvas.

Processing is quite buggy during the initialization phase and weird things like this can happen. My understanding is that Processing is drawing on it's own thread and doesn't handle well synchronization. In your case I think sometimes you're trying to draw something before Processing properly initialize itself.

Try adding a little timer after init() and before render():

Code: Select all

try {
            Thread.sleep(100);
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        }

bsunders
Posts:5
Joined:24 Jul 2013 06:15
Location:Sydney, Australia
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Preview Applet Issue - NullPointerException

Post by bsunders » 24 Jul 2013 07:27

Seems to have worked for me - Thanks !!

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable