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.
IndexProcessing DevelopmentLibraries,  Tool Development › when making library, loadStrings() is static
Page Index Toggle Pages: 1
when making library, loadStrings() is static? (Read 1129 times)
when making library, loadStrings() is static?
Nov 18th, 2005, 8:07am
 
Hey guys. Need your help again. I am so close...

In P5 this is a legal command:

   String file[]=loadStrings(filename);

However when I'm making a library and I want to use any processing function, I would do something like:

   String file[]=PApplet.loadStrings(filename);

In this case, it does not work for loadStrings. The compiler finds the function, but gives me a bogus:

non-static method loadStrings(java.lang.String) cannot be referenced from a static context
String file[]=PApplet.loadStrings(filename);
                    ^

In dev.processing.org, it the source states that

 static public String[] loadStrings(File file)

is static. But

 public String[] loadStrings(String filename)

is not.

What gives? This is the only error preventing me from compiling now. So... very... close...
Re: when making library, loadStrings() is static?
Reply #1 - Nov 18th, 2005, 4:57pm
 
that's because there's no way for a static method to know where the data folder is for loadStrings(). so a File object, which specifies exactly where teh file is, or an InputStream object that's already loaded will work just fine with loadStrings() in a static context.
Re: when making library, loadStrings() is static?
Reply #2 - Nov 18th, 2005, 9:57pm
 
Hm. Okay, I should look into File Objects.

However, is there no way to let a library use the data folder instead of specifying exact paths?
Re: when making library, loadStrings() is static?
Reply #3 - Nov 18th, 2005, 10:45pm
 
you just need to pass the PApplet object to the library... the way that serial, video etc pass in "this" in their constructor. that way you can say parent.loadStrings() and it'll do the sort of thing you want.
Page Index Toggle Pages: 1