title: Problems with creating AsyncTask. text file in an arraylist
body: <p>I'm having some problems creating a method that runs in the background. I'm using Android <code>studio java</code> and want to create a method that loads a text file in an <code>array-list</code>.  I have tried to do this in a public method in a separate class from the activity class. When I run the application, I get problems indicating problems with main thread, so I want to make an <code>asynctask</code>. I have looked all over the internet, but I cannot find anything relevant. Please ask if something was unclear since I'm a beginner. Any help is appreciated!</p>
  
  <p>This is from a class that will send a variable to <code>public void CreateQuestion()</code>, which is below the first code:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_game_action);
  
      Intent callingIntent = getIntent();
      int index = callingIntent.getIntExtra("INDEX",0);      
  
  
      if(index==0){
          mQuestionBox = new QuestionBox();
          try {
              mQuestionBox.createQuestions("hogskoleprovet.txt");
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
      else if(index==1){
          mQuestionBox = new QuestionBox();
          try {
              mQuestionBox.createQuestions("hogskoleprovet.txt");
          } catch (IOException e) {
              e.printStackTrace();
          }
  
  
      }
      else if(index==2){
          mQuestionBox = new QuestionBox();
          try {
              mQuestionBox.createQuestions("hogskoleprovet.txt");
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  </code></pre>
  
  <p>I want to make this code as an asynctask, but I do not know how to do this.</p>
  
  <pre><code>public void createQuestions(String hogskoleprovet)  throws IOException {
  
  
      InputStream iS = sContext.getAssets().open(hogskoleprovet);
      BufferedReader reader = new BufferedReader(new InputStreamReader(iS));
  
      mQuestions = new ArrayList&lt;Question&gt;();
  
  
      String question, answer, answerOne, answerTwo, answerThree, answerFour;
  
  
  
      while (reader.readLine() != null) {
  
          //reading some lines from resource file
          question = reader.readLine();
          answer = reader.readLine();
          answerOne = reader.readLine();
          answerTwo = reader.readLine();
          answerThree = reader.readLine();
          answerFour = reader.readLine();
          Question q = new Question(question, answer, answerOne, answerTwo, answerThree, answerFour);
          mQuestions.add(q);
          break;
      }
  
      reader.close();
  
  
  }
  </code></pre>