【发布时间】:2010-06-19 09:26:25
【问题描述】:
我的应用程序因以下代码中的空指针异常而崩溃。 我在 res/xml/defaults.xml 下有一个 xml 首选项文件 知道为什么会崩溃吗?
public class Preference extends Activity {
public Preference()
{
}
public String getPreference(String key)
{
//it still crashes here
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
String result = settings.getString(key, null);
return result;
}
}
【问题讨论】:
标签: android preferences shared android-preferences sharedpreferences