我是 android 的菜鸟,我正在尝试通过字符串而不是行号来更新 sqlite 行条目。我创建一个条目然后按字符串删除一个条目没有问题。但是,当我尝试通过字符串更新条目时,我得到一个空指针异常?任何帮助是极大的赞赏。
我用于删除工作正常的条目的代码:
public void deleteEntry(String coin) throws SQLException{
String[] whereArgs = new String[] { coin };
ourDatabase.delete(DATABASE_TABLE, KEY_NAME + "=?", whereArgs);
我用于更新不起作用的条目的代码:
public void updateEntry(String mCoin, String mQuantity, String mValue) throws SQLException{
// TODO Auto-generated method stub
String[] whereArgs = new String[] { mCoin };
ContentValues cvUpdate = new ContentValues();
cvUpdate.put(KEY_NAME, mCoin);
cvUpdate.put(KEY_QUANTITY, mQuantity);
cvUpdate.put(KEY_VALUE, mValue);
ourDatabase.update(DATABASE_TABLE, cvUpdate, KEY_NAME + "=?", whereArgs);
}
我的日志猫:
08-27 01:16:13.734: E/Cursor(1886): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.example.portfolio/databases/PortfolioDatabase, table = cointypeTable, query = SELECT _id, cointype_name, cointype_quantity, cointype_value FROM cointypeTable
08-27 01:16:13.734: E/Cursor(1886): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
08-27 01:16:13.734: E/Cursor(1886): at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210)
08-27 01:16:13.734: E/Cursor(1886): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
08-27 01:16:13.734: E/Cursor(1886): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
08-27 01:16:13.734: E/Cursor(1886): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
08-27 01:16:13.734: E/Cursor(1886): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
08-27 01:16:13.734: E/Cursor(1886): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1264)
08-27 01:16:13.734: E/Cursor(1886): at com.example.portfolio.PortfolioDatabase.getData(PortfolioDatabase.java:76)
08-27 01:16:13.734: E/Cursor(1886): at com.example.portfolio.Portfolio.add(Portfolio.java:1305)
08-27 01:16:13.734: E/Cursor(1886): at com.example.portfolio.Portfolio.onItemSelected(Portfolio.java:836)
08-27 01:16:13.734: E/Cursor(1886): at android.widget.AdapterView.fireOnSelected(AdapterView.java:864)
08-27 01:16:13.734: E/Cursor(1886): at android.widget.AdapterView.access$200(AdapterView.java:42)
08-27 01:16:13.734: E/Cursor(1886): at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:830)
08-27 01:16:13.734: E/Cursor(1886): at android.os.Handler.handleCallback(Handler.java:587)
08-27 01:16:13.734: E/Cursor(1886): at android.os.Handler.dispatchMessage(Handler.java:92)
08-27 01:16:13.734: E/Cursor(1886): at android.os.Looper.loop(Looper.java:123)
08-27 01:16:13.734: E/Cursor(1886): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-27 01:16:13.734: E/Cursor(1886): at java.lang.reflect.Method.invokeNative(Native Method)
08-27 01:16:13.734: E/Cursor(1886): at java.lang.reflect.Method.invoke(Method.java:521)
08-27 01:16:13.734: E/Cursor(1886): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-27 01:16:13.734: E/Cursor(1886): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-27 01:16:13.734: E/Cursor(1886): at dalvik.system.NativeStart.main(Native Method)