title: Read JSON file from assets
body: <p>I am trying to read a JSON file from assets in fragment using <code>getAssets()</code>, but the IDE says "can not resolve this method (getAssets())".</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code> public String loadJSONFromAsset() {
      String json = null;
      try {
          InputStream is = getAssets().open("moods.json");
          int size = is.available();
          byte[] buffer = new byte[size];
          is.read(buffer);
          is.close();
          json = new String(buffer, "UTF-8");
      } catch (IOException ex) {
          ex.printStackTrace();
          return null;
      }
      return json;
  
  }
  </code></pre>