-
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"));
vragen[vraag.getNiveaunr()].add(vraag);
}
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.
-
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
line
Vraag vr = ( Vraag)vragen[1].get(0);
to get the information out.
This will give you access to the Vraag
methods.
Hope this helps.
Graham.
Hope this helps
Graham
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 ;-)
http://www.grahamrobinsonsoftware.com
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks