> Hello Knute, this gives error: cannot be referenced from static context.
> Knute Johnson wrote:
>>> Toolkit.createImage(byte[] imagedata)
[quoted text clipped - 15 lines]
>
> Fix your bugs and try again.
Hello, I have this:
Image img;
void applytexture(byte[]texture,etc){
bla-bla;
img=
Toolkit.createImage(texture);
etc
}
javac gives:
non-static method createImage(byte[]) cannot be referenced from a
static context
img=Toolkit.createImage(texture);
^
I've got nothing static.
Thanks for your interest.
Ivan
Lew - 30 May 2007 22:39 GMT
Lew wrote:
>> You show no code and did not quote the error message, so I will make some
>> guesses absent that crucial information:
>> Toolkit is a class, and createImage() a static method,
I was wrong. That's what I get for guessing.
<http://java.sun.com/javase/6/docs/api/java/awt/Toolkit.html#createImage(java.lan
g.String)>
Of course, I would not have made this wrong guess if you had provided the
error message in the first place.
>> These errors have nothing to do with the value of Knute's suggestion.
>>
>> Fix your bugs and try again.
Here I was not wrong.
> Hello, I have this:
> Image img;
> void applytexture(byte[]texture,etc){
> bla-bla;
"Bla-bla" is not good for an SSCCE, since it doesn't compile, but it didn't
matter this time.
> img=
> Toolkit.createImage(texture);
[quoted text clipped - 7 lines]
>
> I've got nothing static.
Yes, you do. The call to createImage() is made through a static context, but
it's not a static method. Ergo, error.
Whenever you call a method just through the class name it's a static call.
Since the method is not declared static, you got an error.
Read the Javadoc on the method. Invoke it through an instance of Toolkit.
<http://java.sun.com/javase/6/docs/api/java/awt/Component.html#getToolkit()>

Signature
Lew
Lew - 30 May 2007 22:46 GMT
Lew wrote:
>> You show no code and did not quote the error message, so I will make some guesses absent that crucial information:
>> Toolkit is a class, and createImage() a static method,
I was wrong. That's what I get for guessing.
<http://java.sun.com/javase/6/docs/api/java/awt/Toolkit.html#createImage(java.lan
g.String)>
Of course, I would not have made this wrong guess if you had provided the
error message in the first place.
>> These errors have nothing to do with the value of Knute's suggestion.
>>
>> Fix your bugs and try again.
Here I was not wrong.
> Hello, I have this:
> Image img;
> void applytexture(byte[]texture,etc){
> bla-bla;
"Bla-bla" is not good for an SSCCE, since it doesn't compile, but it didn't
matter this time.
> img= Toolkit.createImage(texture);
> etc
[quoted text clipped - 4 lines]
> ^
> I've got nothing static.
Yes, you do. The call to createImage() is made through a static context, but
it's not a static method. Ergo, error.
Whenever you call a method just through the class name it's a static call.
Since the method is not declared static, you got an error.
Read the Javadoc on the method. Invoke it through an instance of Toolkit.
<http://java.sun.com/javase/6/docs/api/java/awt/Component.html#getToolkit()>

Signature
Lew