2

I'm getting a null exception while trying to assign a resource to an inputstream

this is my code

InputStream is = null;
    BufferedReader br = null;

    is = this.getResources().openRawResource(R.raw.worldcities);

    br = new BufferedReader(new InputStreamReader(is));

And here is the exception

11-03 15:49:07.476: E/AndroidRuntime(223): Uncaught handler: thread main exiting due    to uncaught exception
11-03 15:49:07.486: E/AndroidRuntime(223): java.lang.NullPointerException
11-03 15:49:07.486: E/AndroidRuntime(223):  at    android.content.ContextWrapper.getResources(ContextWrapper.java:80)
11-03 15:49:07.486: E/AndroidRuntime(223):  at com.karriapps.smartsiddur.Splash.readCSV(Splash.java:253)
一二三
  • 20,716
  • 11
  • 61
  • 73
orelzion
  • 2,384
  • 4
  • 28
  • 44

1 Answers1

1

I think this.getResources() is returning null. Is this in the context of an Activity? If not it getResources will return null. You can see this question as an example: getting a bug at getResources() in android?

In other words make sure that the this keyword is what you think it is.

Community
  • 1
  • 1
James Becwar
  • 1,181
  • 1
  • 10
  • 20