Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing ArrayList from another class
    primarykey
    data
    text
    <p>I am having trouble with accessing my ArrayList from another class. I am following past examples and internet examples but just cannot seem to get it to work.</p> <p>I posted 3 of my classes just to be thorough. The error is in my QuestionView.java class. I documented into my code where and what the error message is.</p> <p>Any other suggestions on any other parts of my code is appreciated. :)</p> <p>QuestionView.java</p> <pre><code>public class QuestionView extends Activity { Quiz q = new Quiz(); ArrayList&lt;Question&gt; queries = new ArrayList&lt;Question&gt;(); queries.getTenQs(); //error here: "Syntax error on token "getTenQs", Identifier expected after this token" @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 &lt; 10; i++) { question.setText(queries.get(i).getQuery()); answer1.setText(queries.get(i).getA1()); answer2.setText(queries.get(i).getA2()); answer3.setText(queries.get(i).getA3()); answer4.setText(queries.get(i).getA4()); //more code... } } } </code></pre> <p>Quiz.java</p> <pre><code> package com.example.test; import java.util.ArrayList; public class Quiz { ArrayList&lt;Question&gt; qList = new ArrayList&lt;Question&gt;(); public static ArrayList&lt;Question&gt; tenQs = new ArrayList&lt;Question&gt;(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 &lt; 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&lt;Question&gt; getTenQs() { return tenQs; } } </code></pre> <p>Question.java</p> <pre><code> package com.example.test; 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; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload