File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes declaring an unitialized 2D array. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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://aspose.com/file-tools
 
subject: declaring an unitialized 2D array.