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 5 of 5

Thread: Array List question

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array List question

    Hey guys, I am using an arraylist for my rpg to store an inventory and one to store the persons name, place of origin, etc.. Anyway, I need to know of a way to be able to use those same array lists with the values stored in them in all of my classes, as I have one class where I am using the array to enter their name etc.. and another one where they are playing the game.

    The problem is that when I try to use the arraylist it gives me back null pointer exception or out of bounds etc.., meaning that there is nothing in the arraylist but I know for sure there is. Also if you do not mind, do you know how if there is a way after you load the arraylist if you are able to use that loaded array list? I know how to load, I just do not know how to use it afterwards.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Array List question

    If you are getting exceptions, there's not much we can do unless you post an SSCCE demonstrating the problem and the full stack trace associated - what you've posted is very general and there's not much help we can give...except...
    am using an arraylist for my rpg to store an inventory and one to store the persons name, place of origin, etc..
    Sorry but this does not sound like a great design...create a class that wraps all this information and have a single list that contains references to objects of that class.

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array List question

    So have a specific class for where they input all of their values? I have that, the only thing that has to be separate is the inventory as that will happen throughout the game, there is no point to have it in that same class, or is there? Couldn't I just keep it separate?

    What I really just need to know is how to use my arraylist in all of my classes that still includes the values that I have already imputed and placed in the array.

  4. #4
    Junior Member
    Join Date
    May 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array List question

    I think I found a work around, it is not efficient at all I dont think. What I did was in my load values, I was able to have them input what file they wanted to load and in the start of the game they load their character which then allows it to read where they started off at. I think I am good now, I will figure out if I need more help later.

  5. #5
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Array List question

    That sounds OK. You might consider looking at the Properties class which makes it easy to load and save named properties in a file.

Similar Threads

  1. Array list returns null
    By Scotty in forum Collections and Generics
    Replies: 3
    Last Post: April 14th, 2011, 06:50 AM
  2. Basic array list
    By Trunk Monkeey in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 24th, 2011, 11:51 AM
  3. question on list manipulation
    By andrefaelnar in forum Java Theory & Questions
    Replies: 11
    Last Post: August 18th, 2010, 07:30 PM
  4. Array List Doubt
    By mhnganesh in forum Collections and Generics
    Replies: 2
    Last Post: July 12th, 2010, 10:21 AM
  5. Replies: 1
    Last Post: November 22nd, 2008, 01:32 PM