Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8912413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:11:29+00:00 2026-06-15T04:11:29+00:00

The error from the LogCat output is pointing to line 37 of QuestionView.java which

  • 0

The error from the LogCat output is pointing to line 37 of QuestionView.java which I will comment into the code below. Below I have 4 snippets of 4 classes. Also I have the output from the LogCat.

MainMenu.java

public class MainMenu extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainmenumain);

    Button button1 = (Button)findViewById(R.id.startBtn);
    Button button2 = (Button)findViewById(R.id.categoriesBtn);
    Button button3 = (Button)findViewById(R.id.highscoresBtn);
    Button button4 = (Button)findViewById(R.id.aboutBtn);

    button1.setOnClickListener(new OnClickListener() {   
        public void onClick(View arg0) {
            Intent intent1 = new Intent(MainMenu.this, QuestionView.class);
            startActivity(intent1);  
        }
    });
//more code...

Question.java

public class Question {
String a1;
String a2;
String a3;
String a4;
int correctAnswer;
String query;

public Question() {
}

public Question(String a1, String a2, String a3, String a4, int correctAnswer, String query) {
    this.a1 = a1;
    this.a2 = a2;
    this.a3 = a3;
    this.a4 = a4;
    this.correctAnswer = correctAnswer;
    this.query = query;        
}

public String getA1() { return a1; }
public String getA2() { return a2; }
public String getA3() { return a3; }
public String getA4() { return a4; }
public String getQuery() { return query; }
public int getCorrectAnswer() { return correctAnswer; }
  }

Quiz.java

public class Quiz {
ArrayList<Question> qList = new ArrayList<Question>();
public static ArrayList<Question> tenQs = new ArrayList<Question>(10);

public Quiz() {
    qList.add(new Question("A", "B", "C", "D", 3, "Question 1?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 2?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 3?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 4?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 5?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 6?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 7?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 8?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 9?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 10?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 11?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 12?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 13?"));
    qList.add(new Question("A", "B", "C", "D", 3, "Question 14?"));
}

public void getRandom10() {
    for(int i = 0; i < 10; i++) {
        Question x = qList.get((int) Math.floor((qList.size()+1)*Math.random()));
        if(tenQs.contains(x) == true) {
            i--;
        } else {
            tenQs.add(x);
        }
    }
}

public ArrayList<Question> getTenQs() { 
    return tenQs;
}
  }

QuestionView.java

public class QuestionView extends Activity {

Quiz quiz = new Quiz();
ArrayList<Question> queries = quiz.getTenQs();

int correctAnswers = 0;
int wrongAnswers = 0;

int answer = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.questionviewmain);

    TextView question = (TextView)findViewById(R.id.question);

    Button answer1 = (Button)findViewById(R.id.answer1);
    Button answer2 = (Button)findViewById(R.id.answer2);
    Button answer3 = (Button)findViewById(R.id.answer3);
    Button answer4 = (Button)findViewById(R.id.answer4);

    for(int i = 0; i < 10; i++) {
        question.setText(queries.get(i).getQuery());  //Error points to here.
        answer1.setText(queries.get(i).getA1());
        answer2.setText(queries.get(i).getA2());
        answer3.setText(queries.get(i).getA3());
        answer4.setText(queries.get(i).getA4());

        answer = queries.get(i).getCorrectAnswer();

        answer1.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                if(answer == 0) {
                    correctAnswers++;
                } else {
                    wrongAnswers++;
                }
            }
        });
//more code...

LogCat

11-12 00:08:40.983: E/AndroidRuntime(4338): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.QuestionView}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
11-12 00:08:40.983: E/AndroidRuntime(4338):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at android.os.Looper.loop(Looper.java:137)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at android.app.ActivityThread.main(ActivityThread.java:4745)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at java.lang.reflect.Method.invokeNative(Native Method)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at java.lang.reflect.Method.invoke(Method.java:511)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at dalvik.system.NativeStart.main(Native Method)
11-12 00:08:40.983: E/AndroidRuntime(4338): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
11-12 00:08:40.983: E/AndroidRuntime(4338):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at java.util.ArrayList.get(ArrayList.java:304)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at com.example.test.QuestionView.onCreate(QuestionView.java:37)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at android.app.Activity.performCreate(Activity.java:5008)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-12 00:08:40.983: E/AndroidRuntime(4338):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)

Any help or input is appreciated! Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:11:30+00:00Added an answer on June 15, 2026 at 4:11 am

    You don’t call your getRandom10() method to initialize list.

    EDIT
    Also you used bad design with class Quiz:

    1. tenQs is static list that you fill with data from non-static list qList.

    2. also tenQs is public that gives possibility to access it directly through class: Quiz.tenQs. I suppose to make it private and non-static and call getRandom10 inside consturtor to be sure of correct initialization of your Quiz.

    3. get your random index as:

    Code:

    Random r = new Random();
    for(int i = 0; i < 10; i++) {
        Question x = qList.get(r.nextInt(qList.size()));
        tenQs.add(x);
    }
    

    I understood. If you use inside for condition < tenQs.size() this for will not be executed cause actual size of tenQs is 0 but capacity is 10. So you must create constant with number of questions in quiz and use it in this for loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting error from inserting array into the database. Error: You have an
I am getting an error from a piece of code. I will only show
I get a parse error from Safari with this code: for (var i=0; i<parent.frames.length;
I have written some code to set data to listview from a webpage. I
This code is working now. LogCat only for lead back problems from other ppl
I am getting this error from the logcat org.apache.http.NoHttpResponseException: The target server failed to
I am getting this error from eway token payment API, soap:ReceiverServer was unable to
I am getting this error from time to time with serialization and I don't
I get the following error from the SQL Script I am trying to run:
I'm getting an Error from Debugger: Error launching remote program: security policy error when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.