本文介绍了在android.content.ContextWrapper.getResources空(ContextWrapper.java:80)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到一个空的异常,而试图将资源分配给一个InputStream
这是我的code
InputStream为= NULL;
BR的BufferedReader = NULL; 是= this.getResources()openRawResource(R.raw.worldcities)。 BR =新的BufferedReader(新的InputStreamReader(是));
这里是例外
15 11-03:49:07.476:E / AndroidRuntime(223):未捕获的处理程序:螺纹主力退出,由于未捕获的异常
11-03 15:49:07.486:E / AndroidRuntime(223):显示java.lang.NullPointerException
11-03 15:49:07.486:E / AndroidRuntime(223):在android.content.ContextWrapper.getResources(ContextWrapper.java:80)
11-03 15:49:07.486:E / AndroidRuntime(223):在com.karriapps.smartsiddur.Splash.readCSV(Splash.java:253)
解决方案
我觉得this.getResources()方法返回null。这是一个活动的背景下?如果不是getResources将返回null。你可以看到这个问题作为一个例子:
在换句话说确保this关键字是什么,你认为它是。
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)
解决方案
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.
这篇关于在android.content.ContextWrapper.getResources空(ContextWrapper.java:80)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!