Results 1 to 4 of 4
  1. #1
    Paul_White is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default Getting a second, third, fourth arraylist from a class

    Guys,

    I have tried everyting I can think of on this one and need some help.
    Perhaps what I am trying to do is not possible but before I spend anymore time seeing:

    Exception in thread "main" java.lang.StackOverflowError
    at Quiz.ReadCSVFile.ColA1(ReadCSVFile.java:155)

    I thought I would ask a question.

    I have a class which reads a .csv file into an arraylist then shuffles it.
    Eack of the columns is then stored in a sparate array "questions", "answer1, answer2" etc.

    The class currently returns the questions.

    What I need to do is be able to access the other ArrayLists.

    I am calling the class with this code

    Questions = ReadCSVFile.ReadCSVFile(filename);
    for(i=0;i<NumberOfQuestions;i++){
    Question = Questions.get(i);

    So far So good I get a shuffled set of questions.

    What I would like to be able to do is call the second third and fourth answers.

    I have tried this:

    Questions = ReadCSVFile.ReadCSVFile(filename);
    Answers1 = ReadCSVFile.ColA1();
    for(i=0;i<NumberOfQuestions;i++){
    Question = Questions.get(i);
    Answer1 = Answers1.get(i);

    This gives me the overflow error.

    I have also tried various lines such as Answers1 = ReadFile.ColA1;

    I feel sure there is a way and perhaps I am just being thick.

    Can someone point me in the right direction can I call a second, third, forth and fifth ArrayList from another class?

    Thanks

    Paul

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Getting a second, third, fourth arraylist from a class

    It depends how your data in the file is formatted. How about having a Question class that has a String for the question and a List<String> of possible answers. Then you read from the file a question and N answers, store them in a Question object and then store that in a List of Questions.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Getting a second, third, fourth arraylist from a class

    Exception in thread "main" java.lang.StackOverflowError
    at Quiz.ReadCSVFile.ColA1(ReadCSVFile.java:155)
    In general you get this when the statement on line 155 causes itself to be carried out again. The "chain of events" can be quite long, but it will look something like:

    Java Code:
    int methodA() {
        return methodB();
    }
    int methodB() {
        return methodA();
    }
    Without seeing code it's hard to be more specific.

    -----

    Java coding conventions call for variables and methods to start with a lowercase letter. Following this style will make your code more readable.

  4. #4
    Paul_White is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default Re: Getting a second, third, fourth arraylist from a class

    Thanks guys.

    I found the loop.

    I thought it would be something simple if pointed in the right direction. You know what its like you try and try without success and lose sight of what is going on.

    Thank you very much.

Similar Threads

  1. Replies: 2
    Last Post: 11-06-2011, 08:19 PM
  2. Get an ArrayList from another class
    By ScienceLife in forum New To Java
    Replies: 5
    Last Post: 04-09-2011, 11:13 AM
  3. Java Arraylist (.get from other class)
    By Kingarmy in forum New To Java
    Replies: 1
    Last Post: 12-28-2010, 09:00 PM
  4. Help passing arraylist to another class
    By adlb1300 in forum New To Java
    Replies: 3
    Last Post: 11-06-2007, 09:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •