Pppplease help me with this error !!

[b][red]This message was edited by Roysterfivenin at 2006-7-20 7:29:54[/red][/b][hr]
Hi,

Before i say anything im a complete beginner so i apologise in advance :)

Im trying to write this code but it wont compile because i get a "non-static method fillRack(java.lang.string) cannot be referenced from a static context" error.

Now i kind of get what it means but i dont want to go changing all my class/instance methods just to accomodate this, so could you please please tell me how to get round this?

Your help is very much appreciated and heres the code...

public void fillRacks()
{
String[] theTiles = new String[7];
for (int a = 1; a <= NUMBER_OF_PLAYERS; a++)
{
for(int b = 0; b < Player.RACK_SIZE; b++)
{
char aTile = this.thePool.pickTile();
String str = new StringBuilder(aTile).toString();
theTiles[b] = str;

}
String allTiles = theTiles[0] + theTiles[1] + theTiles[2] + theTiles[3]+ theTiles[4] + theTiles[5] + theTiles[6];

Player.fillRack(allTiles); <----- this is the offender !!
}
}

Again thanks alot for any help you can give, and remember try and keep any advice simple :)

.Roy


Comments

  • [b][red]This message was edited by Gregry2 at 2006-7-20 17:23:16[/red][/b][hr]
    : [b][red]This message was edited by Roysterfivenin at 2006-7-20 7:29:54[/red][/b][hr]
    : Hi,
    :
    : Before i say anything im a complete beginner so i apologise in advance :)
    :
    : Im trying to write this code but it wont compile because i get a "non-static method fillRack(java.lang.string) cannot be referenced from a static context" error.
    :
    : Now i kind of get what it means but i dont want to go changing all my class/instance methods just to accomodate this, so could you please please tell me how to get round this?
    :
    : Your help is very much appreciated and heres the code...
    :
    : public void fillRacks()
    : {
    : String[] theTiles = new String[7];
    : for (int a = 1; a <= NUMBER_OF_PLAYERS; a++)
    : {
    : for(int b = 0; b < Player.RACK_SIZE; b++)
    : {
    : char aTile = this.thePool.pickTile();
    : String str = new StringBuilder(aTile).toString();
    : theTiles[rightbr]b[leftbr] = str;
    :
    : }
    : String allTiles = theTiles[0] + theTiles[1] + theTiles[2] + theTiles[3]+ theTiles[4] + theTiles[5] + theTiles[6];
    :
    : Player.fillRack(allTiles); <----- this is the offender !!
    : }
    : }
    :
    : Again thanks alot for any help you can give, and remember try and keep any advice simple :)
    :
    : .Roy
    :
    :
    :

    What the error means is that the method fillRack(java.lang.string) is being called from an object that isn't instatiated, that means Player is a type/class, right? You can't do that, since its not a static method. Is this fillRacks() a method in that class 'Player'? Then change the line to

    [green]this[/green].fillRack(allTiles);

    it ensures that the current object's method is called.

    Also, when you post, use code tags
    [leftbr]code[rightbr]c++;[leftbr]/code[rightbr]

    see the 'Stylecodes' box below the large text edit for the message

    thats also why it was bolded, [leftbr]b[rightbr]...[leftbr]/b[rightbr] does this [b]...[/b]
    {2}rIng


  • : public void fillRacks()
    : {
    : String[] theTiles = new String[7];
    : for (int a = 1; a <= NUMBER_OF_PLAYERS; a++)
    : {
    : for(int b = 0; b < Player.RACK_SIZE; b++)
    : {
    : char aTile = this.thePool.pickTile();
    : String str = new StringBuilder(aTile).toString();
    : theTiles[b] = str;
    :
    : }
    : String allTiles = theTiles[0] + theTiles[1] + theTiles[2] + theTiles[3]+ theTiles[4] + theTiles[5] + theTiles[6];
    :
    : Player.fillRack(allTiles); <----- this is the offender !!
    : }
    : }
    :
    : Again thanks alot for any help you can give, and remember try and keep any advice simple :)
    :
    : .Roy

    hi,

    you call the fillRack with a argument which you dont have set in the private method.

    [code]

    : public void fillRacks() <<----
    : {

    and you call the method

    Player.fillRack(allTiles); <----here
    [/code]

    correct woulb be for a only one String

    [code]
    : public void fillRacks([red]String a[/red])
    : {
    [/code]


    for a string array it would be

    [code]

    public void fillRacks([red]String[] a[/red]) <<----
    : {
    [/code]


  • : : public void fillRacks()
    : : {
    : : String[] theTiles = new String[7];
    : : for (int a = 1; a <= NUMBER_OF_PLAYERS; a++)
    : : {
    : : for(int b = 0; b < Player.RACK_SIZE; b++)
    : : {
    : : char aTile = this.thePool.pickTile();
    : : String str = new StringBuilder(aTile).toString();
    : : theTiles[leftbr]b[rightbr] = str;
    : :
    : : }
    : : String allTiles = theTiles[0] + theTiles[1] + theTiles[2] + theTiles[3]+ theTiles[4] + theTiles[5] + theTiles[6];
    : :
    : : Player.fillRack(allTiles); <----- this is the offender !!
    : : }
    : : }
    : :
    : : Again thanks alot for any help you can give, and remember try and keep any advice simple :)
    : :
    : : .Roy
    :
    : hi,
    :
    : you call the fillRack with a argument which you dont have set in the private method.
    :
    : [code]
    :
    : : public void fillRacks() <<----
    : : {
    :
    : and you call the method
    :
    : Player.fillRack(allTiles); <----here [red]//its the function "fillRack(String), not "fillRack[green]s[/green]".[/red]
    : [/code]
    :
    : correct woulb be for a only one String
    :
    : [code]
    : : public void fillRacks([red]String a[/red])
    : : {
    : [/code]
    :
    :
    : for a string array it would be
    :
    : [code]
    :
    : public void fillRacks([red]String[] a[/red]) <<----
    : : {
    : [/code]
    :
    :
    :

    You have different methods, or am I wrong and you're trying to do recursion?

    plus, to Pah, he concatinated them, so they are one String.
    {2}rIng
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion