Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "Not a statement" error?! Help needed with simple java.





    Why am I getting a "Not a statement" error when I try to compile here? I'm just trying to make a no-arg constructor that sets the field numbers[][] to those numbers...

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I believe the syntax you have used for you're arrays is only available when you are declaring it:
    Code:
    private int[][] nums = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};
    I do not believe you can use the curly braces syntax once its been declared and initialized. I may be mistaken on that; it has been awhile since I've done java programming.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    youre not mistaken. This will work:
    Code:
    public class Fun {
    	private static int numbers[][] = {{4,7,3},{2,10,2},{4,5,6}};
    	
    	public static void main(String[] args) {
    		Fun f = new Fun();
    	}
    	
    	public Fun() {
    		System.out.println(numbers[1][1]);
    	}
    }
    I am the luckiest man in the world

  • #4
    New Coder
    Join Date
    Nov 2008
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes ! Array initializations should always be done during its declaration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •