EGH*_*HDK 0 java android sharedpreferences
我在共享的pref上得到一个空指针.但共享首选项始终需要默认值.所以这不会让它变得不可能.
添加此代码段(粗略)给我的问题(根据logcat):
myPrefs = getSharedPreferences("myPrefs", 0);
String lvl_result= myPrefs
.getString(lvl, null);
// Example "A -> a" or null
if (lvl_result.equals(null)) {
gen_lvl();
lvl_result = myPrefs.getString(lvl, null);
}
Run Code Online (Sandbox Code Playgroud)
Logcat(不确定这是否是您想要看到的):
12-04 00:54:42.932: E/AndroidRuntime(763): Caused by: java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
替换代码中的以下行:
if (lvl_result.equals(null)) {
Run Code Online (Sandbox Code Playgroud)
同
if (lvl_result == null) {
Run Code Online (Sandbox Code Playgroud)
如果lvl_result是null然后调用equals此对象的方法将引发空指针异常..
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |