SQLite: Cannot bind argument at index 1 because the index is out of range. The statement has 0 param

SQLite: Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters

SQLite出现了这样的错误

12-25 22:52:50.252: E/AndroidRuntime(813): Caused by: java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range.  The statement has 0 parameters.
12-25 22:52:50.252: E/AndroidRuntime(813):  at android.database.sqlite.SQLiteProgram.bind(SQLiteProgram.java:212)
12-25 22:52:50.252: E/AndroidRuntime(813):  at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:166)
12-25 22:52:50.252: E/AndroidRuntime(813):  at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
12-25 22:52:50.252: E/AndroidRuntime(813):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
12-25 22:52:50.252: E/AndroidRuntime(813):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
12-25 22:52:50.252: E/AndroidRuntime(813):  at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
12-25 22:52:50.252: E/AndroidRuntime(813):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
12-25 22:52:50.252: E/AndroidRuntime(813):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)

代码如下

public Player getPlayer(String name) {
    SQLiteDatabase db = this.getReadableDatabase();

    String[] projection = {
            PlayerEntry.COLUMN_NAME_PLAYER_NAME,
            PlayerEntry.COLUMN_NAME_PLAYED_GAMES,
            };

    String selection =  PlayerEntry.COLUMN_NAME_PLAYER_NAME ;
    String[] selectionArgs = new String[1];
    selectionArgs[0] = name;

    Cursor cursor = db.query(
            PlayerEntry.TABLE_NAME,  // The table to query
            projection,                               // The columns to return
            selection,                                // The columns for the WHERE clause
            selectionArgs,                            // The values for the WHERE clause
            null,                                     // don‘t group the rows
            null,                                     // don‘t filter by row groups
            null                                 // The sort order
            );

    if (cursor != null)
        cursor.moveToFirst();

解决方法如下

String selection =  PlayerEntry.COLUMN_NAME_PLAYER_NAME + "=?";
时间: 2024-10-22 14:41:20

SQLite: Cannot bind argument at index 1 because the index is out of range. The statement has 0 param的相关文章

$(obj).index(this)与$(this).index()异同讲解

$(this).index()在使用jQuery时出镜率非常高,在编写选项卡及轮播图等特效时经常用到,但$(obj).index(this)似乎有点陌生. 为便于理解,以下分两个使用场景加以分析. 场景一: 同级元素标签相同 <ul> <li>one</li> <li>two</li> <li>three</li> <li>four</li> </ul> <script> /

Index Full Scan vs Index Fast Full Scan-1103

[Oracle] Index Full Scan vs Index Fast Full Scan作者:汪海 (Wanghai) 日期:14-Aug-2005 出处:http://spaces.msn.com/members/wzwanghai/ --------------------------------------------------------------------------------Index Full Scan vs Index Fast Full Scan index f

Clustered Index Scan 与 Clustered Index Seek

Clustered Index Scan 与 Clustered Index Seek 在利用 SQL Server 查询分析器的执行计划中,会有许多扫描方式,其中就有 Clustered Index Scan 与 Clustered Index Seek,这二者有什么区别呢? Clustered Index,为聚集索引,表示它们使用的都是聚集索引扫描. Scan 表示它扫描一个范围或者是全部内容,Seek 表示扫描特定范围内的行.也就是说 Scan 并不知道要目标行是哪些,而 Seek 扫描表

查找索引碎片Find Index Fragmentation Details – Slow Index Performance

SQL SERVER – 2005 – Find Index Fragmentation Details – Slow Index Performance Just a day ago, while using one index I was not able to get the desired performance from the table where it was applied. I just looked for its fragmentation and found it wa

Local prefixed index和Local nonprefixed index对select语句的性能影响分析

1.搞清楚两种索引的概念 在比较两种索引对select产生的影响之前,先要搞清楚,什么是Local prefixed index,什么叫Local nonprefixed index.其实,这两种索引,都是属于分区local索引,所以,这两种类型的索引,只有可能在分区表上才会出现. 1.1 什么是Local prefixed index 是指索引中的列,就是分区表的分区键列,或者是索引中的列,包含表的分区键值列,并且为前置位 置在索引最前部位置的本地分区索引. 例如,emp表是按时间范围分区的表

@Index用法——javax.persistence.Index

package com.springup.utiku.model; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Index; import java

index控制器中的index操作

index.php类初始化以后,默认执行indexOp()操作: public function indexOp(){ //输出管理员信息 Tpl::output('admin_info',$this->getAdminInfo()); //getAdminInfo()继承于父类SystemControl //输出菜单 $this->getNav('',$top_nav,$left_nav,$map_nav); //获取菜单,在公共方法中 Tpl::output('top_nav',$top_

添加一个index(add an index)

想ES中存储数据,需要index--存储数据的地方,实际上,index就是一个指向若干物理shard的逻辑命名空间. shard就是更底层的工作单元,每个shard是一个Lucene的实例,每个shard在其控制范围内都是一个完整的搜索引擎.我们的文档被存储,并且被index到shard,但是应用程序是不和shard直接对话的而是和index进行通信. 由于shard是真正储存数据的地方,因此shard表示了ES在你的cluster中是怎么分布数据的.文档被存储在shard中,shard被分配到

$(obj).index(this) 与 $(this).index()的区别

<div id="nav"> <p>111111</p> <p>222222</p> <b>333333</b> <b>444444</b> </div> javascript部分 先引入javascript <script> // $(obj).index(this)基于对象选择下标: $(this).index()基于this同级所有元素的下标: $(