This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes declaring an unitialized 2D array. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "declaring an unitialized 2D array." Watch "declaring an unitialized 2D array." New topic
Author

declaring an unitialized 2D array.

Hung Tang
Ranch Hand

Joined: Feb 14, 2002
Posts: 148
what is the proper syntax in declaring an unitialized 2D array. for example.
The following is fine:
Object [][] array = { {"test1", "test2", "test3"} };
}
but when I type in the following code:
public class Test {
private Object [][] array;

public Test() {
array = { {"test1", "test2", "test3"} }; //error
}
}
I get an error... why and how do I fix it?
Hung Tang
Ranch Hand

Joined: Feb 14, 2002
Posts: 148
Sorry, I know what was the problem. The problem was that I didn't allocate memory for objects using new. So the fix:
array = new Object[][] { {"test1", "test2", "test3"}
};
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: declaring an unitialized 2D array.
 
Similar Threads
protected field
RunTime error with main
define method execute order in java
inheritance for Object class
Interface doubt