Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Array list returns null

  1. #1
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Array list returns null

    In a class (State):

     
    	private int[][] array = board.startArray();
     
     
    	public int[][] getArray() {
    		return array;
    	}
     
    I use the arrayList fine in the rest of the code (startArray works).

    In another class
    State game;
    int[][] testArray = game.getArray();

    Why does the arrayList return null? Im sure I have used this before.

    Thanks


  2. #2
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: Array list returns null

    Quote Originally Posted by Scotty View Post
    Why does the arrayList return null? Im sure I have used this before.
    Thanks
    Looks like the object (of type State) hasn't been initialized.

    If you are certain you are initializing it, you may want to check over to see if you are waiting for user input or something similar. In a past program I created, I found an object wasn't being initialized because it was waiting for user input. Hope this helps.

    And by the way, it looks like you are working with arrays here, not an array list. They are quite different as an array list is dynamic (can grow and shrink) and an array is of fixed size.
    Last edited by vanDarg; April 13th, 2011 at 05:58 PM.
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  3. #3
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Array list returns null

    Sorry, i have used arraylists so much lately i forgot i used an array there.

    Thanks, i will check and see what i get

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Array list returns null

    Thread moved to - Collections and Generics
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. Array of strings Null Pointer error
    By FredrichGauss in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 3rd, 2011, 12:43 AM
  2. Basic array list
    By Trunk Monkeey in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 24th, 2011, 10:51 AM
  3. [SOLVED] Error: Null Exception on Array of classes
    By g000we in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2010, 08:14 AM
  4. Array List Doubt
    By mhnganesh in forum Collections and Generics
    Replies: 2
    Last Post: July 12th, 2010, 10:21 AM
  5. How do you set an object in array to null value?
    By Arius in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 25th, 2010, 02:50 AM