I received this crash report in the Google Play console. I have never experienced such a failure on my device and emulator.
Caused by: java.lang.NullPointerException:
at android.preference.PreferenceManager.getDefaultSharedPreferencesName (PreferenceManager.java:498)
at android.preference.PreferenceManager.getDefaultSharedPreferences (PreferenceManager.java:487)
at DictionaryDB2.getHistoryWords (DictionaryDB2.java)
or .hasObject (DictionaryDB2.java)
it getHistoryWords
public List<Bean> getHistoryWords() {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MyApp.getAppContext());
String historyNum = SP.getString("history","50");
SQLiteDatabase db = initializer.getReadableDatabase();
String sql = "SELECT * FROM " + HISTORY_NAME +
" WHERE " + STATUS + " ORDER BY " + STATUS + " DESC LIMIT " + historyNum ;
Cursor cursor = db.rawQuery(sql, null);
List<Bean> wordList = new ArrayList<Bean>();
while(cursor.moveToNext()) {
int id = cursor.getInt(0);
String english = cursor.getString(1);
String malay = cursor.getString(2);
wordList.add(new Bean(id, english, malay));
}
cursor.close();
db.close();
return wordList;
}
This is MyApp:
public class MyApp extends Application {
private static Context context;
public void onCreate() {
super.onCreate();
MobileAds.initialize(this, "my admob ");
MyApp.context = getApplicationContext();
}
public static Context getAppContext() {
return MyApp.context;
}
}
How to solve this problem?
source
share