DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004

    Getting information out off an Object

    Hi all,

    I started learning Java a few months ago and right now i'm trying to make my first "bigger" program, a simulation of the game WWTBAM.

    Everything went fine, but now I've hit rock bottom, and I've been looking at the code for so long I guess the solution to my problem is dead easy but it just escapes me.

    so here's what I'd appreciated be solved.

    First of all, questions had to be loaded out off an access database, for that I used the following (which works fine by the way)

    for (int i = 1; i <=15; i++)
    vragen[i] = new ArrayList();

    while (setVragen.next())
    Vraag vraag = new Vraag(setVragen.getInt("VraagNr"),setVragen.getString( "Vraag"),setVragen.getString( "A"),setVragen.getString( "B"),setVragen.getString( "C"),setVragen.getString( "D"),setVragen.getString( "Correct"), setVragen.getInt("Niveau"));

    So as you can see I create an arraylist made out of 15 arraylists, one for each difficulty level of questions, so each contains a number of Objects "Vraag" (which means "question").

    All still going well, then however in the main part of my GUI I need to load a question from the arraylist, so first of all I do this:

    ArrayList vragen[] = Database.getVragen();

    Now I can (or should be able) to use the Arraylist in my program.

    Next I want to load one object from that ArrayList so I add the following line of code:
    Object vr = vragen[1].get(0);

    If I'm not mistaken I've now got an Object vr which has the exact same contents as the first object of the first Arraylist in the Arraylist vragen.

    Now however I need to get the info, added to that object by the constructor, back into seperate variables. And that's where I'm stuck ... how do I get the data from the object split up into the seperate variables I need.

    Or is there a better way to load the things I need from the Arraylist (I need to be able to specify the difficulty level and question/object number when loading the question)

    Any help would be appreciated.

  2. #2
    Join Date
    May 2004
    Durham, UK

    Getting info out of an object

    Hi Scaramanga,

    I may be missing something, as you
    haven't posted the class Vraag
    but I think that you should be using the

    Vraag vr = ( Vraag)vragen[1].get(0);

    to get the information out.

    This will give you access to the Vraag

    Hope this helps.
    Hope this helps

    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, and if they get mad, you are a mile away and you have their shoes ;-)


  3. #3
    Join Date
    May 2004
    Yup that did the trick ... as I read your post I realized what I had forgotten.

    Thank god you won't have to cast an object anymore in 1.5 ... it's a real pain in 1.4.2

    Thanks !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.