Sign in to follow this  

java arrays

This topic is 4278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to learn java at the moment, and although for the most part i find it to be very easy to understand, there are some things that bite me in the ass. Maybe its just me, but anyways ... i need to create an array of objects ... well, object references as we are forced into with java ... and the following code leaves the array pointing to null ? Object[] ta = new Object[1]; ta[0] = new Country("Country4"); and i have no idea why ... anyone care to shed some light on this for me? Any help appreciated, thanks :)

Share this post


Link to post
Share on other sites
Quote:
Original post by mbruenjes
If Country extends Object, you shouldn´t have any problems.

Every class extends Object in Java.

I also do not see anything wrong with this code that would ta null...

Share this post


Link to post
Share on other sites
Quote:
Original post by xyuri
Object[] ta = new Object[1];
ta[0] = new Country("Country4");

This is perfectly legal code (assuming Country is defined well). The problem must be buried elsewhere. Perhaps you have a variable hiding? Please post more of the relevant code.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry to do this but i found the problem ... slight oversight ...

I learned that java initiallises array's to null so thats what i thought it was, but in fact the way i was testing it (System.out.println(ta[0].toString());) was the problem ... i had disabled some properties in the Country class which the toString() function was using, and it was one of those value that was null, not the array value :-)

Share this post


Link to post
Share on other sites

This topic is 4278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this