Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-10-2008, 10:22 PM   PM User | #1
erad
New to the CF scene

 
Join Date: Dec 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
erad is an unknown quantity at this point
"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...
erad is offline   Reply With Quote
Old 12-10-2008, 10:54 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 12-11-2008, 01:37 PM   PM User | #3
Roelf
Senior Coder

 
Join Date: Jun 2002
Location: Zwolle, The Netherlands
Posts: 1,110
Thanks: 2
Thanked 28 Times in 28 Posts
Roelf is on a distinguished road
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]);
	}
}
Roelf is offline   Reply With Quote
Old 12-12-2008, 09:08 AM   PM User | #4
If I Were A Boy
New Coder

 
Join Date: Nov 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
If I Were A Boy is an unknown quantity at this point
Yes ! Array initializations should always be done during its declaration.
If I Were A Boy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 03:26 PM.


Advertisement
Log in to turn off these ads.