提问人:Moustafa Asaad 提问时间:11/23/2019 最后编辑:JacksMoustafa Asaad 更新时间:11/24/2019 访问量:107
在设备上使用 sqlite 数据库时出现 NullPointerException,但模拟器工作正常
NullPointerException when using sqlite database on device but emulator works fine
问:
我正在尝试使用预定义的数据库 SQLite 开发一个字典应用程序,这是它崩溃时的日志。
2019-11-23 08:26:40.432 16132-16349/offline.english.dictionary W/CrashlyticsCore: Cannot send reports. Settings are unavailable.
2019-11-23 08:26:40.433 16132-16132/offline.english.dictionary E/UncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.database.CursorWindow.getNumRows()' on a null object reference
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:162)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:149)
at android.support.v4.widget.CursorAdapter.getCount(CursorAdapter.java:217)
at android.widget.AutoCompleteTextView$PopupDataSetObserver$1.run(AutoCompleteTextView.java:1416)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7073)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
这是SQLITECURSOR.java,它显示错误行:162
catch (RuntimeException ex) {
closeWindow();
throw ex;
}
}
根据崩溃日志,这是SQLiteCursor.java:149
mCount = mQuery.fillWindow(mWindow, requiredPos, requiredPos, true);
根据崩溃日志,这是 CursorAdapter.java:217
private final Runnable updateRunnable = new Runnable() {
@Override
public void run() {
final AutoCompleteTextView textView = mViewReference.get();
if (textView == null) {
return;
}
final ListAdapter adapter = textView.mAdapter;
if (adapter == null) {
return;
}
textView.updateDropDownForFilter(adapter.getCount());
}
};
}
}
这是处理程序.java:873,99 根据崩溃日志
private static void handleCallback(Message message) {
message.callback.run();
}
public void dispatchMessage(Message msg) {
if (msg.callback != null) {
handleCallback(msg);
} else {
if (mCallback != null) {
if (mCallback.handleMessage(msg)) {
return;
}
}
handleMessage(msg);
}
}
这是Looper.java:214,根据崩溃报告。
if (logSlowDispatch) {
showSlowLog(slowDispatchThresholdMs, dispatchStart, dispatchEnd, "dispatch", msg);
}
if (logging != null) {
logging.println("<<<<< Finished to " + msg.target + " " + msg.callback);
}
答: 暂无答案
评论