Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Having problems calling a non-static method for a static context

Reply
Thread Tools

Having problems calling a non-static method for a static context

 
 
iMohed@live.se
Guest
Posts: n/a
 
      05-12-2009
I guess the title says it all. I just dont understand why i cant cal
my Main.play() from my Model class. Both in the same package.

Model class short :

public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
clickButton(source);
}

public void clickButton(Object o) {
int i = 0;
for (MButton s : this.but) {
if (s == o) {
Main.play(i);
}
}
}

Main class short :

public void play(int k) throws IOException {
while (game.finish == false) {
game.doTurn(k);
int j = 0;
for (Model.Square squares : game.sq) {
communication[j] = squares.value;
j++;
}
gameGfx.setColors(communication);
}
}

Any ideas guys and gals ??
Mohamed Haidar.
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      05-12-2009
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I guess the title says it all. I just dont understand why i cant cal
> my Main.play() from my Model class. Both in the same package.
>
> Model class short :
>
> public void actionPerformed(ActionEvent e) {
> Object source = e.getSource();
> clickButton(source);
> }
>
> public void clickButton(Object o) {
> int i = 0;
> for (MButton s : this.but) {
> if (s == o) {
> Main.play(i);
> }
> }
> }
>
> Main class short :
>
> public void play(int k) throws IOException {
> while (game.finish == false) {
> game.doTurn(k);
> int j = 0;
> for (Model.Square squares : game.sq) {
> communication[j] = squares.value;
> j++;
> }
> gameGfx.setColors(communication);
> }
> }
>
> Any ideas guys and gals ??
> Mohamed Haidar.


Either new Main().play() or make play static.

--

Knute Johnson
email s/nospam/knute2009/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      05-13-2009
(E-Mail Removed) wrote:
> I guess the title says it all.


Not really. The convention here is for the body of a post to stand on its own.

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: non-static method cannot be referenced from a static context Johannes Beekhuizen Java 0 08-05-2005 05:33 PM
non-static method cannot be referenced from a static context Johannes Beekhuizen Java 14 08-05-2005 04:48 PM
newbie Java question - non-static method cannot be referenced from a static context G. Burton Java 2 02-21-2004 07:45 PM
Question: non-static method dummy(int) cannot be referenced from a static context Michael Java 3 01-27-2004 08:45 PM
Please help: Non-static method wait(long) cannot be referenced from static context Gary Java 1 01-16-2004 11:35 PM



Advertisments