title: Reaching json-file in res/raw folder from Java code Android
body: <p>I am having some trouble trying to figure out how to reach my quiz.js (JSON-file) from within my assets folder in the Android project.</p>
  
  <p>This is the method i use to load questions from a JSON file:</p>
  
  <pre><code>public ArrayList&lt;Question&gt; loadQuestions() throws IOException, JSONException {
      ArrayList&lt;Question&gt; questions = new ArrayList&lt;Question&gt;();
      BufferedReader reader = null;
      try{
          // Open and read the file into a StringBuilder
          //InputStream in = mContext.openFileInput(mContext.getResources().getString(R.raw.quiz));
          //InputStream in = mContext.getResources().openRawResource(R.raw.quiz);
          InputStream in = mContext.getAssets().open("quiz.js");
          reader = new BufferedReader(new InputStreamReader(in));
          StringBuilder jsonString = new StringBuilder();
          String line = null;
          while ((line = reader.readLine()) != null) {
              // Line breaks are omitted and irrelevant
              jsonString.append(line);
          }
          // Parse the JSON using JSONTokener
          JSONArray array = (JSONArray) new JSONTokener(jsonString.toString()).nextValue();
  
          // Build the array of crimes from JSONObjects
          for(int i=0; i&lt; array.length(); i++){
              questions.add(new Question(array.getJSONObject(i)));
          }
      }
      catch (FileNotFoundException e){
          // Ignore this one; it happens when starting fresh
      }
      finally{
          if(reader != null){
              reader.close();
          }
      }
      return questions;
  }
  </code></pre>
  
  <p>This is the JSON file json.js:</p>
  
  <pre><code>[
  {
      "imageURI": "100",
      "question": "Hva betyr skiltet?",
      "answers": [
           "Farlig sving til venstre",
           "Farlig sving til høyre",
           "Blah..",
           "Blahh.."
       ],
      "correct": 0
  },
  {
      "imageURI": "101",
      "question": "Lorem ipsum dolor sit amet...",
      "answers": [
           "String 1",
           "String 2",
           "String 3",
           "String 4"
       ],
      "correct": 2
  }
  </code></pre>
  
  <p>]</p>
  
  <p>This is from the activity where i try to use the data from the JSON</p>
  
  <pre><code>public class QuizActivity extends Activity {
  
  private ArrayList&lt;Question&gt; questions;
  private QuizJSONSerializer mSerializer; 
  
  private static final String TAG = "QuizActivity";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_quiz);
  
  
      // This is where i get the loadQuestions from
      mSerializer = new QuizJSONSerializer(getApplicationContext());
  
      try{
          questions = mSerializer.loadQuestions();
      }
      catch (Exception e){
          questions = new ArrayList&lt;Question&gt;();
          Log.e(TAG, "Error loading questions: ", e);
      }
  
      ImageView iv = (ImageView) findViewById(R.id.question_image);
      iv.setImageResource(R.drawable.mdpi_farlig_sving);
  
      TextView tv = (TextView) findViewById(R.id.question_text_view);
      if(questions == null){
          tv.setText("Something wrong with the array!");
      }
      else{
          tv.setText(questions.get(0).getQuestion());
      }
  
      Button b1 = (Button) findViewById(R.id.option_one);
      b1.setText("String 1");
  
      Button b2 = (Button) findViewById(R.id.option_two);
      b2.setText("String 2");
  
      Button b3 = (Button) findViewById(R.id.option_three);
      b3.setText("String 3");
  
      Button b4 = (Button) findViewById(R.id.option_four);
      b4.setText("String 4");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Seems like the JSON file never gets loaded in because the code from my exception always run.</p>
  
  <p>Is there something missing in the JSON file?</p>
  
  <p>Any good advice?</p>