为什么我得到GETDIR一个NullPointerException异常? [英] Why do I get a NullPointerException on getDir?

查看:296
本文介绍了为什么我得到GETDIR一个NullPointerException异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我明白,如果犯规存在,但GETDIR将创建一个目录。但我崩溃的:

I understood that getDir will create a directory if it doesnt exist yet. But I'm crashing on:

File dir= getDir(file,Context.MODE_PRIVATE);

文件的类型为String。 logcat中显示:

file is of type String. logcat shows:

12-29 21:56:09.456: ERROR/AndroidRuntime(631): java.lang.NullPointerException
12-29 21:56:09.456: ERROR/AndroidRuntime(631):     at android.content.ContextWrapper.getDir(ContextWrapper.java:198)

这里的code:

Here's the code:

public class ReportHome extends Application{
public ReportHome(String message, String file){
    …some code…
    inf(tosend,file);
}
public void inf(String c, String file){
    File dir= getDir(file,Context.MODE_PRIVATE);

BTW:什么是格式化的logcat的多条线路的伎俩正确

btw: what is the trick to format more than one line of logcat correctly?

推荐答案

您确保文件参数不是null?

Are you sure that the file argument isn't null?

如果不是的话,那么另一种可能性是,你没有在一个健全的环境下运行这一点。

If it's not, then the other possibility is that you're not running this in a sane environment.

纵观<一个href=\"http://www.google.com/$c$csearch#uX1GffpyOZk/core/java/android/content/ContextWrapper.java&q=android.content.ContextWrapper.java%20getDir&type=cs&l=196\"相对=nofollow>来源$ C ​​$ C为GETDIR(),唯一的可能就是 MBASE (保存当前的<一个私有变量code>上下文)为空。我不太确定,将如何发生的,没有看到你的code的其余部分。

Looking at the source code for getDir(), the only other possibility is that mBase (a private variable that holds the current Context) is null. I'm not quite sure how that would happen without seeing the rest of your code.

这篇关于为什么我得到GETDIR一个NullPointerException异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆