title: Android App, reading textfile from res
body: <p>I have looked through tons different solutions to this problem, but nothing seems to work.</p>
  
  <p>I am trying to make an app that reads in a text file and displays parts of it on the screen. I'm having a problem reading the file though, and I don't know what I am doing wrong. I've been debugging the code, and it throws a IO java exception (fileNotFound).. It does not execute the file-reading parts of the code.. I never reach the while loop.. It throws the exception before I reach it.</p>
  
  <p>I put the file in the <code>/res/raw directory</code></p>
  
  <p>The error output in the LogCat is: <code>threadid=3 Thread exiting due to uncaught exception</code></p>
  
  <p>When I compile the code it also complains about a nullPointerException on line 48 which I do not understand since I don't seem to reach that part of the code in the debugger.</p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>public class AndroidReadTest extends Activity {
  
  HashMap&lt;String, ArrayList&lt;String&gt;&gt; table = new HashMap();
  
  Random rand = new Random();
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      String category = "";
      ArrayList&lt;String&gt; temp = new ArrayList();
  
  
      try {
  /**         AssetFileDescriptor descriptor = getAssets().openFd("AndroidReadTest/res/raw/questions");
          BufferedReader in = new BufferedReader(new FileReader(descriptor.getFileDescriptor())); */
  
          BufferedReader in = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.questions))); // I have tried adding .txt
  
          while(in.readLine()!=null){
  
              ......
  
          }
          table.put(category, temp);
  
  
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      Button b = (Button) findViewById(R.id.button1);
      b.setOnClickListener(click);    
  }
  
  public String get(ArrayList&lt;String&gt; questions){
  
      int temp = questions.size();        
      String str = questions.get(rand.nextInt(temp));
      return str;
  }
  
  private OnClickListener click = new OnClickListener(){
      public void onClick(View V){
          TextView text = (TextView) findViewById(R.id.textView1);
          text.append(get(table.get("---Cathegory")));    
      }
  };
  
  
  }
  </code></pre>