Forums > Java

static outlet method ?

July 20, 2008 | 2:39 pm

Hello,

I’m trying to use outlet() in a static method. the compilator tells me :

on-static method outlet(int,int) cannot be referenced from a static
context

This is strange because the post() method works fine.
Does anybody knows how I can do ?

many thanks !!!!

O..////


July 20, 2008 | 2:57 pm

Olivier –

I think if you associate the non-static method explicitly with an object
you can call it from the static context (i.e. the dynamic object has to
exist or be referenced). This may work:

MaxObject.outlet();

or you may have to do this:

MaxObject MyMaxObject = new MaxObject();
MyMaxObject.outelt();

but I’m not sure how well they will function in an mxj object context
(the
outlet method then called may not be associated properly with the
mxj object you are building). And I may be wrong…

brad

http://music.columbia.edu/~brad

On Jul 20, 2008, at 10:39 AM, olivier pasquet wrote:

> Hello,
>
> I’m trying to use outlet() in a static method. the compilator tells
> me :
>
> on-static method outlet(int,int) cannot be referenced from a static
> context
>
> This is strange because the post() method works fine.
> Does anybody knows how I can do ?
>
> many thanks !!!!
>
> O..////


July 20, 2008 | 3:37 pm

I don’t think outlet() can be expected to work in a static method.

post() works because there’s only one Max window. You may have many instances of your mxj object and therefore many outlets that could be the target.

What are you trying to do?

Do you want the int to be sent from the outlet of only one of your instances or ALL of them? (The latter of these might warrant the use of a static method, e.g., you could keep track of all of your instances and use a static method to send a message out of all of your objects’ right outlets.)


July 20, 2008 | 10:47 pm

Hi,

olivier pasquet wrote:
> This is strange because the post() method works fine.
> Does anybody knows how I can do ?

This is not strange at all. If you read the javadoc for MaxObject,
you’ll see that post is declared as

static void post ( java.lang.String message )

On the other hand, every outlet method is declared as non-static. Since
you can’t call instance methods from a static method (how would that be
possible anyway?), but you can call other static methods, this behavior
is quite ordinary.

Cheers,
Adam


July 21, 2008 | 10:16 am

Hi Adam,

Thanks for your response!!

> but you can call other static methods, this behavior is quite
ordinary.
< How then can I do if I want outlet() behave as a static method ?

Why post() is static and not outlet() ?


July 21, 2008 | 10:31 am

Quote: Olivier Pasquet wrote on Mon, 21 July 2008 11:16
—————————————————-
>
> Why post() is static and not outlet() ?
>
—————————————————-

Because post() prints messages in the Max window and there is only one Max window.


Viewing 6 posts - 1 through 6 (of 6 total)