2012-12-20 121 views
0

我得到这个错误:转换为String []

The method query(String, String[], String, String[], String, String, String) in the type SQLiteDatabase is not applicable for the arguments (String, String[], String, String, null, null, null) 

和代码负责:

public Cursor getDomanda(String id) { 
      List<categorie> categorie = new ArrayList<categorie>(); 

      Cursor cursor = database.query(MySQLiteHelper.TABLE_SONDAGGI, 
       allCategorieColumns, MySQLiteHelper.COLUMN_ID + "=", id, null, null, null); 

      cursor.moveToFirst(); 
      while (!cursor.isAfterLast()) { 
       categorie categoria = cursorToCategorie(cursor); 
       categorie.add(categoria); 
       cursor.moveToNext(); 
      } 
      // Make sure to close the cursor 
      // cursor.close(); 
      return cursor; 
      } 

在另一侧:

long strcategory = getIntent().getExtras().getLong("categoriaId"); 
Cursor values = datasource.getDomanda(Long.toString(strcategory)); 

我做错了什么? 我需要将长整数转换为String[],但到底是什么?String[]?:D 顺便说一下......查询是正确的吗? 我的意思是

database.query(MySQLiteHelper.TABLE_SONDAGGI, 
        allCategorieColumns, MySQLiteHelper.COLUMN_ID + "=", id, null, null, null); 

select from tableSondaggi where _id = $id ? 
+0

你问的是什么数组? – SLaks

+0

srsly?什么是String []'? – njzk2

+0

对不起,我知道阵列:D我只是有点累:D:D –

回答

2

第四个参数必须是一个String[],而不是一个String

您需要用new String[] { id }替换id才能创建一个由单个元素(您的id)组成的数组。

Cursor cursor = database.query(MySQLiteHelper.TABLE_SONDAGGI, 
      allCategorieColumns, MySQLiteHelper.COLUMN_ID + "=", new String[] { id }, null, null, null); 
1

这应该是诀窍。

Cursor cursor = database.query(MySQLiteHelper.TABLE_SONDAGGI, 
      allCategorieColumns, MySQLiteHelper.COLUMN_ID + "=", new String[] { id }, null, null, null); 

但是:也许读一些关于基本编程的书可能是必要的。数组(例如String[])非常有用...