user1489886
user1489886

Reputation: 131

context.getResources().openRawResource() crashes the app

I'm trying for a while to make android read from a text file that I already have in the R.raw folder.

I have the function void readfile(Context context) that contains the line

InputStream is = context.getResources().openRawResource(R.raw.data);

However when I try to run the app it crashes at that exact line. Can you tell me a workaround? Or another way to read from that file?

Upvotes: 0

Views: 2651

Answers (1)

AMerle
AMerle

Reputation: 4354

There is obviously a problem with the given context. You should post your logcat.

There is 2 ways to solve your problem.

  1. Pass a correct context: see what is wrong with your program and why the given context is not correct.
  2. Extend Application, and save the application context in a static variable: see this post

Upvotes: 1

Related Questions