title: Struggling with null referencing issues while calling a function in Flutter
body: <p>I'm currently trying to create an app with Flutter that helps a user memorize French verbs. Here's a snippet of my code:</p>
  <pre><code>class Quiz {
    List&lt;String&gt; questionList;
    List&lt;String&gt; answerList;
    Quiz(List questionList, List answerList){
      this.questionList = questionList;
      this.answerList = answerList;
    }
  }
  </code></pre>
  <p>As you can see, I've created a Quiz class that takes in two parameters: a list of test questions, and a list of their corresponding answers.</p>
  <p>I then define a function that actually returns a 'Quiz' object. Here it is:</p>
  <pre><code>Quiz quizGenerator (questions, answers) {
    final Set&lt;int&gt; indexS = Set();
    for (int i = 0; i &lt;= 9; i++){
      indexS.add(Random().nextInt(49));
    }
    List&lt;String&gt; testQ;
    List&lt;String&gt; testA;
    List&lt;int&gt; indexes = indexS.toList();
    for (int i = 0; i &lt;= 9; i++){
      var element = indexes[i];
      testQ[i] = questions[element];
      testA[i] = answers[element];
    }
    var newTest = Quiz(testQ, testA);
    return newTest;
  }
  
  </code></pre>
  <p>I wanted this function to return a 'Quiz' object that consisted of ten verbs to test that were randomly picked from a larger list of fifty verbs called &quot;questions&quot;, as well as their corresponding answers from the larger list &quot;answers&quot;. Since I was planning to pick the test questions by generating random index numbers, and I didn't want verbs to repeat in a test, I created a set of integers called 'indexS', and populated it with ten random numbers in the range of 0-49. This set essentially contained the index numbers of the ten questions that would be asked from the larger &quot;questions&quot; list.</p>
  <p>I then converted the set to a list of integers called &quot;indexes&quot;. I also created two other lists called &quot;testQ&quot; and &quot;testA&quot; that would actually contain the ten test questions and their corresponding answers respectively. These two lists would be the 'Quiz' object's properties. From there, I used a for loop to fill 'testQ' and 'testA' with the ten test questions and their answers by using the random index numbers stored in the list 'indexes'. The end result of all this was that a 'Quiz' object was returned by 'quizGenerator'.</p>
  <p>However, I'm getting the following error when I try to call 'quizGenerator':</p>
  <pre><code>The following NoSuchMethodError was thrown while handling a gesture:
  The method '[]=' was called on null.
  Receiver: null
  Tried calling: []=(0, &quot;to open&quot;)
  </code></pre>
  <p>I apologize if the answer to this problem is obvious, but I've barely just started programming, and I've scoured the internet for days without much luck. Let me know if something is unclear or if you'd need anything else to better answer my question. Thank you!</p>
  <p>Edit:</p>
  <p>Here are the declarations for &quot;questions&quot; and &quot;answers&quot;:</p>
  <pre><code>List&lt;String&gt; answers = ['rentrer', 'vivre', 'rendre', 'tenir', 'oublier', 'travailler', 'manger', 'entrer', 'devenir', 'commencer', 'payer', 'tirer', 'ouvrir', 'changer', 'excuser', 'dormir', 'occuper', 'marcher', 'envoyer', 'apprendre', 'boire', 'garder', 'montrer', 'asseoir', 'porter', 'prier', 'servir', 'écrire', 'retrouver', 'gagner', 'acheter', 'rappeler', 'lire', 'monter', 'quitter', 'emmener', 'toucher', 'continuer', 'raconter', 'repondre', 'sauver', 'rencontrer', 'fermer', 'valoir', 'compter', 'bouger', 'apporter', 'décider', 'vendre', 'expliquer',];
  
  List&lt;String&gt; questions = ['to bring in','to live','to return','to hold','to forget','to work','to eat','to go in','to become','to start','to pay','to pull','to open','to change','to forgive','to sleep','to occupy','to walk','to send','to learn','to drink','to look after','to show','to sit down','to carry','to pray','to serve','to write','to find', 'to win', 'to buy', 'to remind', 'to read', 'to go up', 'to leave', 'to take', 'to touch', 'to continue', 'to tell', 'to answer', 'to save', 'to meet', 'to close', 'to hold', 'to count', 'to move', 'to bring', 'to decide', 'to sell', 'to explain',];
  </code></pre>