Java Forum / First Aid / November 2005
nullpointerexception
Huub - 07 Nov 2005 13:02 GMT Hi,
I've made a piece of code for dilation image morphology. This is a method being called from the main class. It compiles ok, but it goes wrong with a NullPointerException at (x):
private PlanarImage pi_src, pi_best; KernelJAI kernel; float[] kernel_data = new float[] {1.0F, 1.0F, 1.0F, 0.0F, 0.0F, 0.0F, -1.0F, -1.0F, -1.0F};
public void erosie(String image_keuze) { try { pi_src = JAI.create("fileload", image_keuze); } catch (IllegalArgumentException iae) { } kernel = new KernelJAI(3, 3, kernel_data); try { pi_best = JAI.create("erode", pi_src, kernel); } catch (IllegalArgumentException iae) { } (x) add(new ScrollingImagePanel(pi_best, 640, 480)); pack(); show(); }
Any idea or is more code necessary?
Thanks
Huub
Bjorn Abelli - 07 Nov 2005 13:16 GMT "Huub" wrote...
> I've made a piece of code for dilation image morphology. This is a method > being called from the main class. It compiles ok, but it goes wrong with a [quoted text clipped - 28 lines] > > Any idea or is more code necessary? At "x" there are two objects that could cause the NullPointerException:
- new ScrollingImagePanel(pi_best, 640, 480) - and pi_best itself
The first one "could" throw a NullPointerException depending on how the constructor for ScrollingImagePanel is written, and what it expects from the arguments to fulfill.
But my best bet is that "pi_best" simply is null. To test it you could just throw in a console ouput like
System.out.println( (pi_best == null) );
...to see if it's null.
If that's the case, I'd suggest that you fill in something useful in the catch-clause, to see what really happened at its "creation":
try { pi_best = JAI.create("erode", pi_src, kernel); } catch (IllegalArgumentException iae) { iae.printStackTrace(); }
That would give you further information on the matter...
// Bjorn A
Huub - 07 Nov 2005 13:46 GMT > But my best bet is that "pi_best" simply is null. To test it you could just > throw in a console ouput like > > System.out.println( (pi_best == null) ); > > ...to see if it's null. It's null indeed, even pi_src is. Looks like an argument problem.
> If that's the case, I'd suggest that you fill in something useful in the > catch-clause, to see what really happened at its "creation": [quoted text clipped - 9 lines] > > That would give you further information on the matter... Yes, it wants all parameters having valid, i.e. non-null, input.
Thanks.
Bjorn Abelli - 07 Nov 2005 15:48 GMT "Huub" wrote...
>> But my best bet is that "pi_best" simply is null. >> To test it you could just throw in a console ouput like [quoted text clipped - 4 lines] > > It's null indeed, even pi_src is. Looks like an argument problem. Then your next step should be to be sure that you send in the right arguments in the first place.
public void erosie(String image_keuze) { try { pi_src = JAI.create("fileload", image_keuze); } catch (IllegalArgumentException iae) { System.out.println(image_keuze); iae.printStackTrace(); } ... }
...to check that's what the factorymethod "create" asks for...
http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/medi a/jai/JAI.html
(or http://tinyurl.com/9kb2v)
// Bjorn A
Roedy Green - 07 Nov 2005 16:53 GMT On Mon, 7 Nov 2005 16:48:56 +0100, "Bjorn Abelli" <bjorn_abelli@DoNotSpam.hotmail.com> wrote, quoted or indirectly quoted someone who said :
>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/medi a/jai/JAI.html it looks as though it wants an operation e.g. "convolve" as the first parm. See if you can find a list of the various operations somewhere.
I see notes in the javadoc that hint other operations are "lookup", "fileload", "Pyramid" and "MIP map" ParameterBlock pb = (new ParameterBlock()).add("SomeFile.tif"); RenderedOp node = new RenderedOp("fileload", pb, null);
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 07 Nov 2005 13:49 GMT >{ > pi_best = JAI.create("erode", pi_src, kernel); [quoted text clipped - 6 lines] > show(); > } Except for EOFException, never create an empty catch. At least do an e.printStackTrace().
Looks like you got an IllegalArgumentException. You swallowed it, leaving pi_best null.
I don't think you read the stack trace properly. I would expect the exception to happen inside ScrollingImagePanel.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Huub - 07 Nov 2005 13:53 GMT >>{ >> pi_best = JAI.create("erode", pi_src, kernel); [quoted text clipped - 15 lines] > I don't think you read the stack trace properly. I would expect the > exception to happen inside ScrollingImagePanel. stacktrace says this:
operation "FileLoad" requires parameter at index 0 to be non-null operation "Dilate" requires all source objects to be valid input; a null is supplied
Apart from that, ScrollingImagePanel is stated as depricated. What should I use in it's place?
Roedy Green - 07 Nov 2005 14:08 GMT >Apart from that, ScrollingImagePanel is stated as depricated. What >should I use in it's place? There is no such JDK class as ScrollingImagePanel. It might be something in JAI or it might be something you invented. If it is yours, perhaps ScrollingImagePanel USES a deprecated method.
If it is part of JAI, look it up in the JavaDoc. They often tell you what they recommend to replace it.
Please copy/paste code, stack traces and error messages verbatim. Don't paraphrase them.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Andrew Thompson - 07 Nov 2005 14:11 GMT ...
> Apart from that, ScrollingImagePanel is stated as depricated. What > should I use in it's place? Usually the JavaDocs list the replacement when something has been deprecated, e.g. <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Window.html#show()>
HTH
Roedy Green - 07 Nov 2005 14:18 GMT >stacktrace says this: > >operation "FileLoad" requires parameter at index 0 to be non-null >operation "Dilate" requires all source objects to be valid input; a null >is supplied that is not a stacktrace. A stacktrace has a big list of who called who at which lines.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Huub - 07 Nov 2005 14:24 GMT > that is not a stacktrace. A stacktrace has a big list of who called > who at which lines. You mean this:
java.lang.IllegalArgumentException: operation "FileLoad" requires parameter at index 0 to be non-null. at javax.media.jai.JAI.createNS(JAI.java:1091) at javax.media.jai.JAI.create(JAI.java:977) at javax.media.jai.JAI.create(JAI.java:1412) at Vision.dilatie(Vision.java:77) at SabineDDS.actionPerformed(SabineDDS.java:191) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786) at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258) at javax.swing.AbstractButton.doClick(AbstractButton.java:289) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113) at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943) at java.awt.Component.processMouseEvent(Component.java:5100) at java.awt.Component.processEvent(Component.java:4897) at java.awt.Container.processEvent(Container.java:1569) at java.awt.Component.dispatchEventImpl(Component.java:3615) at java.awt.Container.dispatchEventImpl(Container.java:1627) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128) at java.awt.Container.dispatchEventImpl(Container.java:1613) at java.awt.Window.dispatchEventImpl(Window.java:1606) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.EventQueue.dispatchEvent(EventQueue.java:456) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137) at java.awt.EventDispatchThread.run(EventDispatchThread.java:100) java.lang.IllegalArgumentException: operation "Dilate" requires all source objects to be valid input; a null is supplied. at javax.media.jai.JAI.createNS(JAI.java:1091) at javax.media.jai.JAI.create(JAI.java:977) at javax.media.jai.JAI.create(JAI.java:1584) at Vision.dilatie(Vision.java:87) at SabineDDS.actionPerformed(SabineDDS.java:191) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786) at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258) at javax.swing.AbstractButton.doClick(AbstractButton.java:289) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113) at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943) at java.awt.Component.processMouseEvent(Component.java:5100) at java.awt.Component.processEvent(Component.java:4897) at java.awt.Container.processEvent(Container.java:1569) at java.awt.Component.dispatchEventImpl(Component.java:3615) at java.awt.Container.dispatchEventImpl(Container.java:1627) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128) at java.awt.Container.dispatchEventImpl(Container.java:1613) at java.awt.Window.dispatchEventImpl(Window.java:1606) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.EventQueue.dispatchEvent(EventQueue.java:456) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137) at java.awt.EventDispatchThread.run(EventDispatchThread.java:100) true true java.lang.NullPointerException at javax.media.jai.widget.ImageCanvas.initialize(ImageCanvas.java:127) at javax.media.jai.widget.ImageCanvas.<init>(ImageCanvas.java:179) at javax.media.jai.widget.ImageCanvas.<init>(ImageCanvas.java:188) at javax.media.jai.widget.ScrollingImagePanel.<init>(ScrollingImagePanel.java:91) at Vision.dilatie(Vision.java:94) at SabineDDS.actionPerformed(SabineDDS.java:191) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786) at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258) at javax.swing.AbstractButton.doClick(AbstractButton.java:289) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113) at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943) at java.awt.Component.processMouseEvent(Component.java:5100) at java.awt.Component.processEvent(Component.java:4897) at java.awt.Container.processEvent(Container.java:1569) at java.awt.Component.dispatchEventImpl(Component.java:3615) at java.awt.Container.dispatchEventImpl(Container.java:1627) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128) at java.awt.Container.dispatchEventImpl(Container.java:1613) at java.awt.Window.dispatchEventImpl(Window.java:1606) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.EventQueue.dispatchEvent(EventQueue.java:456) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137) at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
Roedy Green - 07 Nov 2005 14:52 GMT >java.lang.IllegalArgumentException: operation "FileLoad" requires >parameter at index 0 to be non-null. [quoted text clipped - 3 lines] > at Vision.dilatie(Vision.java:77) > at SabineDDS.actionPerformed(SabineDDS.java:191) it left your code at Vision.dilatie at line 77. So presumably whatever you did wrong should be detectable there. Then it went off into JAI.create and eventually died at JAI.createNS line 1091 where it finally deteced the problem and THREW an IllegalArgumentException (not a NullPointerException!!!)
And politely explained why it was upset. Presumably you gave it some sort of file parameter to create, which it did not like when it finally got around to using it the FileLoad.
So it looks like the problem is you got the parameters wrong to JAI.create.
JAI is not a package most people use. So how about you quote the javaDoc for create, and also post your code for the create call along with the code you use to declare the various parameters.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Bjorn Abelli - 07 Nov 2005 15:41 GMT > Apart from that, ScrollingImagePanel is stated as depricated. What should > I use in it's place? It doesn't say in the actual Javadocs
http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/index.html
...but according to some other forum it's been replaced by
DisplayJAI
http://swjscmail1.java.sun.com/cgi-bin/wa?A2=ind0003&L=jai-interest&P=R3606
// Bjorn A
Oliver Wong - 07 Nov 2005 20:43 GMT > Except for EOFException, never create an empty catch. At least do an > e.printStackTrace(). If you're just going to print a stack trace, then don't catch the exception at all; just throw it. When it reaches the top, it'll do a stack trace automatically anyway.
- Oliver
Roedy Green - 08 Nov 2005 03:50 GMT > If you're just going to print a stack trace, then don't catch the >exception at all; just throw it. I think he means don't catch it, just declare throws IOException on the method header.
public void doSomething() throws IOException
The key is you must NOT write code like this:
catch ( IOException e ) { }
to ignore/swallow the exception.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Oliver Wong - 08 Nov 2005 15:20 GMT >> If you're just going to print a stack trace, then don't catch the >>exception at all; just throw it. [quoted text clipped - 11 lines] > > to ignore/swallow the exception. Yes, that is what I meant. Thanks for clarifying.
- Oliver
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|