从一行游标中提取信息-Android SQLite

从一行游标中提取信息-Android SQLite,android,string,android-sqlite,android-cursor,Android,String,Android Sqlite,Android Cursor,我有这样一个问题,我试图用东西填充字符串[],但我这样做的方式不起作用。到目前为止,我的应用程序接收XML数据,对其进行解析,将其放入单独的表中,并在列表中显示项目。我正在处理详细视图,这就是我被卡住的地方。我一直收到一个nullpointer异常错误,因为即使字符串[]具有正确数量的“插槽”(我已经检查过了),它们也是空的 这就是功能: public String[] getDetails(String id, int param){ Cursor cursor = getDetai

我有这样一个问题,我试图用东西填充字符串[],但我这样做的方式不起作用。到目前为止,我的应用程序接收XML数据,对其进行解析,将其放入单独的表中,并在列表中显示项目。我正在处理详细视图,这就是我被卡住的地方。我一直收到一个nullpointer异常错误,因为即使字符串[]具有正确数量的“插槽”(我已经检查过了),它们也是空的

这就是功能:

public String[] getDetails(String id, int param){

    Cursor cursor = getDetailsCursor(id, param);

    String[] details = new String[cursor.getColumnCount()];
    int itty=0;

    if (cursor.moveToFirst()){
           do{
              details[itty] = cursor.getString(itty);

              itty++;
           }while(cursor.moveToPosition(itty));
        }
        cursor.close();

    return details;

}
在我们提问之前:它是正确的光标,从有时通过的信息和ColumnCount,我知道它是正确的光标

我以前问过你们问题,你们似乎马上就知道是什么了。这可能是我对这个小项目的最后一个问题

更新
public String[]getDetails(字符串id,int参数){
Cursor Cursor=getDetailsCursor(id,参数);
字符串[]详细信息=新字符串[cursor.getColumnCount()],名称=新字符串[cursor.getColumnCount()];
int i=0;
cursor.moveToFirst();
name=cursor.getColumnNames();
cursor.moveToFirst();
对于(i=0;i

这是我目前拥有的代码。我将尝试您的解决方案,看看它们是否有相同的结果。

cursor.moveToPosition或cusor.moveToNext在行上迭代。如果您想读取行中的所有列,请遵循以下代码

public String[] getDetails(String id, int param){
 Cursor cursor = getDetailsCursor(id, param);
 if (cursor!= null && cursor.moveToFirst()){
  int columnCount = cursor.getColumnCount();

// below while loop will execute only once if there is only one row.
//如果您确定只有一行,则不需要While循环。这种逻辑是可以理解的 //可以扩展以创建字符串数组列表

  do{
    String[] details = new String[columnCount];
    for(int i=0;i<columnCount;i++){
        details[i] = cursor.getString(i);
    }
// Now details array has information of all columns in current row.

  }while(cursor.moveToNext());
 }
 cursor.close();
 return details;
}
do{
字符串[]详细信息=新字符串[columnCount];

对于(int i=0;icursor.moveToPosition或cusor.moveToNext,对行进行迭代。如果要读取行中的所有列,请遵循以下代码

public String[] getDetails(String id, int param){
 Cursor cursor = getDetailsCursor(id, param);
 if (cursor!= null && cursor.moveToFirst()){
  int columnCount = cursor.getColumnCount();

// below while loop will execute only once if there is only one row.
//如果您确定只有一行,则不需要While循环。此逻辑可以 //可以扩展以创建字符串数组列表

  do{
    String[] details = new String[columnCount];
    for(int i=0;i<columnCount;i++){
        details[i] = cursor.getString(i);
    }
// Now details array has information of all columns in current row.

  }while(cursor.moveToNext());
 }
 cursor.close();
 return details;
}
do{
字符串[]详细信息=新字符串[columnCount];

对于(int i=0;icursor.moveToPosition或cusor.moveToNext,对行进行迭代。如果要读取行中的所有列,请遵循以下代码

public String[] getDetails(String id, int param){
 Cursor cursor = getDetailsCursor(id, param);
 if (cursor!= null && cursor.moveToFirst()){
  int columnCount = cursor.getColumnCount();

// below while loop will execute only once if there is only one row.
//如果您确定只有一行,则不需要While循环。此逻辑可以 //可以扩展以创建字符串数组列表

  do{
    String[] details = new String[columnCount];
    for(int i=0;i<columnCount;i++){
        details[i] = cursor.getString(i);
    }
// Now details array has information of all columns in current row.

  }while(cursor.moveToNext());
 }
 cursor.close();
 return details;
}
do{
字符串[]详细信息=新字符串[columnCount];

对于(int i=0;icursor.moveToPosition或cusor.moveToNext,对行进行迭代。如果要读取行中的所有列,请遵循以下代码

public String[] getDetails(String id, int param){
 Cursor cursor = getDetailsCursor(id, param);
 if (cursor!= null && cursor.moveToFirst()){
  int columnCount = cursor.getColumnCount();

// below while loop will execute only once if there is only one row.
//如果您确定只有一行,则不需要While循环。此逻辑可以 //可以扩展以创建字符串数组列表

  do{
    String[] details = new String[columnCount];
    for(int i=0;i<columnCount;i++){
        details[i] = cursor.getString(i);
    }
// Now details array has information of all columns in current row.

  }while(cursor.moveToNext());
 }
 cursor.close();
 return details;
}
do{
字符串[]详细信息=新字符串[columnCount];

对于(int i=0;i而言,
光标
方法
移动到…
移动正在处理的行而不是列。将
int
传递给调用
getString(…)
定义列号。您基本上需要这样做

if (cursor.moveToFirst()) {
    for (int itty = 0; itty < cursor.getColumnCount(); itty++) {
        details[itty] = cursor.getString(itty);
    }
}
if(cursor.moveToFirst()){
对于(int itty=0;itty
光标
方法
移动到…
移动正在处理的行而不是列。将
int
传递给调用
getString(…)
定义列号。基本上需要这样做

if (cursor.moveToFirst()) {
    for (int itty = 0; itty < cursor.getColumnCount(); itty++) {
        details[itty] = cursor.getString(itty);
    }
}
if(cursor.moveToFirst()){
对于(int itty=0;itty
光标
方法
移动到…
移动正在处理的行而不是列。将
int
传递给调用
getString(…)
定义列号。基本上需要这样做

if (cursor.moveToFirst()) {
    for (int itty = 0; itty < cursor.getColumnCount(); itty++) {
        details[itty] = cursor.getString(itty);
    }
}
if(cursor.moveToFirst()){
对于(int itty=0;itty
光标
方法
移动到…
移动正在处理的行而不是列。将
int
传递给调用
getString(…)
定义列号。基本上需要这样做

if (cursor.moveToFirst()) {
    for (int itty = 0; itty < cursor.getColumnCount(); itty++) {
        details[itty] = cursor.getString(itty);
    }
}
if(cursor.moveToFirst()){
对于(int itty=0;itty
cursor.getString(itty),这里itty是一列,但稍后您会将其作为行号进行递增。getString(itty),这里itty是一列,但稍后您会将其作为行号进行递增。getString(itty),这里itty是一列,但稍后您会将其作为行号进行递增。getString(itty),这是一个列,但稍后您将其作为行号进行递增。不,我想您误解了…只有一行,有多个列…它是可变的。我不需要每行中的字符串,但需要一行中的多个字符串。好的,明白了。那么为什么要在光标行上进行迭代。您需要在列上进行迭代。请检查k更新的解决方案。希望有帮助!不,我想你误解了…只有一行,有多个列…它是可变的。我不需要每行有一个字符串,但需要一行有多个字符串。好的,明白了。那你为什么要迭代光标行。你需要迭代列。请检查更新的解决方案。希望它有帮助!不,我认为是你误解了…只有一行,有多个列…它是可变的。我不需要每行的一个字符串,但需要一行的多个字符串。好的,明白了。那你为什么要在光标行上迭代。你需要在列上迭代。请检查更新的解决方案。希望有帮助!不,我想你误解了…只有一行,即h多列…它是可变的。我不需要stri