1

I'm trying to fill this array floorArray through the method fillUp in my Golv class.

This is the code from my main Class:

Golv golv = new Golv(this);

int[] floorArray = new int[FRAMEWIDTH];
golv.fillUp(floorArray); 

And this is the relevant snippet from my Golv class:

public void fillUp(int[] floorArray){
    floorArray[0] = 5;
}

This produces ""VariableDeclaratorID" expected after this token." and "syntax error misplaced constructs" after the golv.fillUp(floorArray); row.

What am I doing wrong?

4
  • 3
    You need to add that statement - invocation, inside some method. Commented Aug 24, 2013 at 14:51
  • 2
    Note that it's unusual to use non-english variable/class names. Feel free to name them whatever you want, but your next question might be a lot more complicated, and then it'd be a pity if only swedes could help. Commented Aug 24, 2013 at 14:55
  • 1
    Maybe try to create default constructor first. Commented Aug 24, 2013 at 14:56
  • @BenjaminLindqvist did you created a constructor for Golv with argument of type of your second class..?? Commented Aug 24, 2013 at 17:33

1 Answer 1

1

You can't just put your source code directly inside a class, you need to put it in a method.
BAD:

public class Test{

    System.out.println("Hello");

}

GOOD:

public class Test{

    public static void main(String[] args){
        System.out.println("Hello");
    }

}

So, to wrap it up: Every piece of code that for example executes a method HAS to be in a method block. You CAN declare (create) variables outside a method but if you ever execute a piece of code it has to be inside a method! (else it will give you an exception)


Edit: Read the comment on your question! Kᴇʏsᴇʀ is 100% right! Please use English for everything when you're programming/developing anything.. ALWAYS use english, it WILL help!

(also, I guess you are from Sweden because golv is a swedish word and your name is kinda swedish :P, I'm from sweden too :) )

EDIT 2: Changed all words from 'function' to 'method' because: In Java there are methods, but no functions. – JB Nizet

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.