我在谷歌收到此崩潰報告Play開發者控制檯:安卓:NullPointerException異常中的onCreate
java.lang.RuntimeException: Unable to start activity ComponentInfo{ZhuangDictActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:138)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at ZhuangDictActivity.showChooseDictDialog(ZhuangDictActivity.java:560)
at ZhuangDictActivity.onCreate(ZhuangDictActivity.java:339)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
... 11 more
這是的onCreate下:
sharedPreferences = getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
dictName = sharedPreferences.getString(PREFERENCES_DICT_NAME, null);
if (dictName == null) {
showChooseDictDialog(false);
} else {
modifyDictVar(dictName);
setTitle(loadDictInfo());
initDbFile();
databaseHelper.initDb();
}
的showChooseDictDialog:
private void showChooseDictDialog(boolean cancelable) {
AlertDialog.Builder dictChooseBuilder = new AlertDialog.Builder(this);
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return filename.contains(".ifo");
}
};
dictFilenames = dictPathFile.list(filter);
if (dictFilenames.length > 0) {
dictChooseBuilder.setItems(dictFilenames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dictName = dictFilenames[which].substring(0, dictFilenames[which].indexOf(".ifo"));
modifyDictVar(dictName);
initDbFile();
databaseHelper.initDb();
if (new File(ifoFileName).isFile()) {
setTitle(loadDictInfo());
}
if (new File(idxFileName).isFile() && dictFile.isFile()) {
sharedPreferences.edit().putString(ZhuangDictActivity.PREFERENCES_DICT_NAME, dictName).commit();
// dbHelper.dropTable(tableName);
if (!databaseHelper.isTableExist(tableName)) {
databaseHelper.beginTransaction();
databaseHelper.createTable(tableName);
for (char c = 'a'; c <= 'z'; c++) {
String temp = DatabaseHelper.transTableName(c);
databaseHelper.createTable(temp);
}
databaseHelper.setTransactionSuccessful();
databaseHelper.endTransaction();
new LoadDictIndexAsyncTask().execute(dictName);
}
} else {
showDialog(getResources().getString(R.string.choose_dict_content));
}
}
});
dictChooseBuilder.setCancelable(cancelable).setTitle(getResources().getString(R.string.choose_dict_title))
.create().show();
} else {
dictChooseBuilder.setCancelable(cancelable).setMessage(
getResources().getString(R.string.choose_dict_content)).create().show();
}
}
完整ZhuangDictAcitivity.java的源代碼可在此處獲得:https://code.google.com/p/zhuang-dict/source/browse/trunk/ZhuangDict/src/cn/wangdazhuang/zdict/ZhuangDictActivity.java
任何人都知道這個解決方案?
您能否提供有關發生錯誤的位置的更多信息? – Tafari
使用該應用程序版本構建的ZhuanDictActivity.java版本的第560行是什麼? – laalto
嘗試在alertdialog中提供上下文作爲'AlertDialog.Builder dictChooseBuilder = new AlertDialog.Builder(ZhuangDictActivity.this);' – GrIsHu