How do I create an ArrayList that can accept multiple datatypes?

The project I am currently tasked with completing has the following task:

In startNewGame() , create a new ArrayList and assign it to the questions member variable you defined in task 2. Then, add all of your Question objects to the ArrayList .

The question object accepts int and String datatypes and as a result when I attempt to add this to my ArrayList I receive a cannot find symbol error (which I often resolve by adding a missed data type). However, in this instance I’m not sure how to proceed and may be guilty (as I often can be) of overthinking this.

Below I have added my code and I’d be grateful for any pointers as I’m well and truly stuck.

import java.util.ArrayList;

public class MainActivity {

    // TODO #1: add integer member variables here
    int currentQuestionIndex;
    int totalCorrect;
    int totalQuestions;

    // TODO #2: add ArrayList member variable here
    ArrayList<Questions> question = new ArrayList<Questions>;

    // TODO #3 add startNewGame() here 
    public void startNewGame(){
      Question question1 = new Question(921238,"How tall is the Eiffel tower?", "1024 ft", "1063 ft", "1124 ft", "1163 ft", 1);
      Question question2 = new Question(107343, "Who invented the computer algorithm?", "Charles Babbage", "John Carmack", "Alan Turing", "Ada Lovelace", 3);
      Question question3 = new Question(748294, "What is the name for the patch of skin found on your elbow?", "Elbow Skin", "Fascia Elbora","Wenis", "Todd", 2);
      question.add(new Questions(question1, question2, question3));

The arraylist needs to hold “objects”, in this case the object is Question which holds all the following information, ints and strings. Basically, you don’t need an arraylist that holds multiple types, it’s possible though.

You’d define whichever symbol is missing, there’s no voodoo involved in that. Alternatively, if you used a symbol that does not exist, pick a different one that does.

public class MainActivity {
    public static void main() {
        tnsauhnatu i = 5;
} error: cannot find symbol
        tnsauhnatu i = 5;
  symbol:   class tnsauhnatu
  location: class MainActivity
1 error

presumably you would here change tnsauhnatu to int

no, it doesn’t. look at how you defined it, you’ve defined what the type of the elements are. additionally, you should already have decided what you meant to do with that list. you have to consider what you meant. what did you mean to put in that list? (and you have to decide what you mean before you write code, otherwise who is deciding what should happen?)

I suggest commenting out everything under todo 3 and getting the previous things to compile first. You shouldn’t be writing additional code when what you have so far doesn’t compile.

@steinnkarlsson895474 I don’t think they’re trying to mix types, only Question’s are being added to it

yeh maybe, tbh i only read the title. I was just going through the problem earlier of making an arraylist that ‘needed’ to mix ints and string since i thought i needed that. Then i realised i only needed an arraylist for objects.

Thank you for the reply.

I’m not entirely sure how this would work?

My Question object is parametrised with two int data types and five String. If I have to return this object to my ArrayList surely if I declare that as an int it will throw an error?

This is the part I’m stuck on.

I have made some modifications to my code:

ArrayList question;

question = new ArrayList<>();

you’re not putting ints or strings in your arraylist.
you’re putting questions in your arraylist
there’s just one thing.

if you read your error message it says what symbol isn’t defined and then you either define it, or you use something that is defined.