We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › nullPointerExpt from getCodeBase()
Page Index Toggle Pages: 1
nullPointerExpt from getCodeBase() (Read 1248 times)
nullPointerExpt from getCodeBase()
Aug 4th, 2007, 5:08pm
 
Any suggestion will be welcomed.
Thank you.

[code]
void setup() {
 println(getCodeBase());
}  
[code]

java.lang.NullPointerException
at java.applet.Applet.getCodeBase(Applet.java:146)
at Temporary_1161_9684.setup(Temporary_1161_9684.java:9)
at processing.core.PApplet.handleDisplay(PApplet.java:1285)
at processing.core.PGraphics.requestDisplay(PGraphics.java:680)
at processing.core.PApplet.run(PApplet.java:1454)
at java.lang.Thread.run(Thread.java:552)
Re: nullPointerExpt from getCodeBase()
Reply #1 - Aug 4th, 2007, 11:43pm
 
try something like this:

Code:

void setup ()
{
if ( online ) {
// only works when run online, in a browser
println( "online:" );
println( getCodeBase() );
} else {
// locally run, processing-ide, application
try{
println( "local:" );
println( new URL( "file:"+sketchPath("") ) );
} catch ( Exception e ) {
e.printStackTrace();
}
}
}


F
Re: nullPointerExpt from getCodeBase()
Reply #2 - Aug 5th, 2007, 3:27am
 
Thank you for your Many advice, fjen !
I'will follow your advice, and will report the result.

Re: nullPointerExpt from getCodeBase()
Reply #3 - Aug 5th, 2007, 5:37am
 
The advice of fjen was perfect.Thank you, fjen.
But my problem is still existing.

I'm trying to make some Library, and wish to access a image file as a library's resource.
*Can I do that thing?
*If can, where the image file is to be placed?

thank you
Re: nullPointerExpt from getCodeBase()
Reply #4 - Aug 5th, 2007, 9:17am
 
After a web survey, I can solve my problem, as following.
It seem like to be well, both on eclipse, pde and application.
Thank you.

URL resource = null;
Image img = null;
if (waitingImg==null) {
 resource = this.getClass().getResource("WiiStart.jpg");
 if (parent.online && resource!=null) {
          img = parent.getImage(resource);
  }  else if (resource!=null) {
          img = Toolkit.getDefaultToolkit().getImage(resource);
  }
  if (img!=null) waitingImg = parent.loadImageSync(img);
}
Re: nullPointerExpt from getCodeBase()
Reply #5 - Aug 5th, 2007, 8:06pm
 
the whole point of the "data" folder and the loadImage() command are to avoid situations like this. just put the image in the data folder and use loadImage(), which will work in both cases. for more about the data folder and setting up sketches, read help -> getting started.

if you need a java image instead of a PImage, see examples elsewhere on the board for creating an Image object from a PImage.
Re: nullPointerExpt from getCodeBase()
Reply #6 - Aug 6th, 2007, 6:22am
 
Thank you, fry.
My target is loading PImage from my lib's jar file, other than the 'data' folder.
Would you suggest me a more elegant way ?, if exists.
Re: nullPointerExpt from getCodeBase()
Reply #7 - Sep 12th, 2007, 2:01pm
 
use the java methods getClass().getResourceAsStream() to pull things out of the library jar files.
Re: nullPointerExpt from getCodeBase()
Reply #8 - Sep 12th, 2007, 4:58pm
 
thanks, i'll try it.
Page Index Toggle Pages: 1