2013-02-22 88 views
0

我被定义如下创建数据库表: -光标未正确初始化?

public static final String Create_Database2= "CREATE TABLE " + Table_Name2 + "(" 
       + play20 + " INTEGER PRIMARY KEY, " 
       + play1 + " LONG, " 
       + play2 + " LONG, " 
       + play3 + " INTEGER, " 
       + play4 + " INTEGER, " 
       + play5 + " LONG, " 
       + play6 + " TEXT, " 
       + play7 + " TEXT, " 
       + play8 + " TEXT, " 
       + play9 + " TEXT, " 
       + play10 + " TEXT, " 
       + play11 + " INTEGER, " 
       + play12 + " INTEGER, " 
       + play13 + " INTEGER, " 
       + play14 + " INTEGER, " 
       + play15 + " INTEGER, " 
       + play16 + " INTEGER, " 
       + play17 + " TEXT, " 
       + play18 + " INTEGER, " 
       + play19 + " TEXT" 
       + ") "; 

现在我从它像这样得到的数据: -

public Cursor getcontent() 
     { 
      Cursor d= database.query(DatabaseHandler.Table_Name2,allColumns,selection, null, null,null,null); 
     } 
public String[] allColumns = { DatabaseHandler.play5, DatabaseHandler.play6,DatabaseHandler.play7, 
      DatabaseHandler.play8,DatabaseHandler.play9,DatabaseHandler.play10 }; 
String selection="playlist_id=100813"; 

以上是我的数据选择的标准

Cursor r=X.getcontent(); 
      if (r.getCount() > 0) { 
      r.moveToFirst(); 
       do { 
       String id = r.getString(r.getColumnIndex("content_id")); 
         al.add(id); 
        String from_date =r.getString(r.getColumnIndex("from_date")); 
        String to_date =r.getString(r.getColumnIndex("to_date")); 
        String from_time =r.getString(r.getColumnIndex("from_time")); 
        String to_time =r.getString(r.getColumnIndex("to_time")); 
        String days =r.getString(r.getColumnIndex("days")); 
        String duration =r.getString(r.getColumnIndex("duration")); 
       } while (r.moveToNext()==true); 
       r.close(); 
       } else { 
       Log.i("TAG"," No value found"); 
      }  

我得到这个错误logcat

02-22 15:37:04.565: E/AndroidRuntime(11544): FATAL EXCEPTION: main 
02-22 15:37:04.565: E/AndroidRuntime(11544): java.lang.RuntimeException: 
Unable to start activity ComponentInfo{com.example.webdata/com.example.webdata.MainActivity}:java.lang.IllegalStateException: 
Couldnt read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. 

我在做什么错在这里?

+0

您可以检查的getContent()不返回空? – Anukool 2013-02-22 10:16:56

+0

是的,它不返回空我已经检查过它 – 2013-02-22 10:21:27

+0

所以我认为它明确..尝试在database.query()方法中传递正确的参数。 – Anukool 2013-02-22 10:31:33

回答

-1

检查条件,如果(r.moveToFirst())的前进