在用SQLiteDatabase查询有两种方法:
1. the first :
- Cursor cursor = db.query(TABLE_NAME, null,"account=?", new String[]{useraccount}, null, null, null);
- while(cursor.moveToFirst)
Cursor cursor = db.query(TABLE_NAME, null,"account=?", new String[]{useraccount}, null, null, null);
while(cursor.moveToFirst)
}
2. the second
- String existSql = "select * from "+TABLE_NAME+" where account=?";
- Cursor cursor = db.rawQuery(existSql, new String[]{useraccount});
- <pre class="html" name="code">while(cursor.moveToFirst)</pre><br>
- <p></p>
- <pre></pre>
这个java.lang.IIIegalArgumentException 的解释如下:
找到这个问题对应的出现错的行:
- Cursor c = db.rawQuery("select * from tablename where cntrct_no=? AND product_code=?",
- new String[]{cntrct_no, product_code});
- while (c.moveToNext()) { }
Cursor c = db.rawQuery("select * from tablename where cntrct_no=? AND product_code=?",
new String[]{cntrct_no, product_code});
while (c.moveToNext()) { }
错误出在:在查询sql数据结果的时候,你是绑定的是第一个,然而第一个出现了null,所以就跑出异常了。
String existSql = "select * from "+TABLE_NAME+" where account=?";
Cursor cursor = db.rawQuery(existSql, new String[]{useraccount});
<div class="dp-highlighter bg_html"><div class="bar"><div class="tools"><strong>[html]</strong> <a target=_blank title="view plain" class="ViewSource" href="http://blog.csdn.net/nobaddd/article/details/7273112#">view plain</a><a target=_blank title="copy" class="CopyToClipboard" href="http://blog.csdn.net/nobaddd/article/details/7273112#">copy</a><a target=_blank title="print" class="PrintSource" href="http://blog.csdn.net/nobaddd/article/details/7273112#">print</a><a target=_blank title="?" class="About" href="http://blog.csdn.net/nobaddd/article/details/7273112#">?</a></div></div><ol class="dp-xml"><li class="alt"><span><span>while(cursor.moveToFirst) </span></span></li></ol></div><pre class="html" style="display: none;" name="code">while(cursor.moveToFirst)
因为这次粗心大意..浪费了半天 -_-|||必须记录下来以此为鉴.
版权声明:本文为博主原创文章,未经博主允许不得转载。