Reputation: 8904
I am trying to get all items on my db while the first step is my db is empty and after that I insert some items from my db .I am inserting correctly(dont have any errors and inserting num is bigger that 0). but after the inserting when trying to get all items back from the db get null on dbAdper.getAllTitles();
here is my code
public ArrayList<Object> getWantedItemsList(Context context,String item,String item2,String item3,String item4){
ArrayList<Object> ListRssLinkAndTitle=new ArrayList<Object>();
DBAdapter dbAdper=new DBAdapter(context);
Cursor CursorDb =null;
try
{
dbAdper.open();
dbAdper.drop();
dbAdper.createTable();
dbAdper.insertTitle(context,"Ynet", "http://www.ynet.co.il/Integration/StoryRss2.xml", "rtl",null);
dbAdper.insertTitle(context,"BBC", "http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml", "rtl",null);
CursorDb =dbAdper.getAllTitles();
CursorDb.moveToFirst();
if (CursorDb.getCount()>0)
do
{
ListRssLinkAndTitle.add(new rssLinkAndTitle(CursorDb.getString(CursorDb.getColumnIndex(item)),CursorDb.getString(CursorDb.getColumnIndex(item2)),CursorDb.getString(CursorDb.getColumnIndex(item3)),CursorDb.getBlob(CursorDb.getColumnIndex(item4))));
}
while(CursorDb.moveToNext());
}
finally{
if (CursorDb.equals("null"))
CursorDb.close();
dbAdper.close();
return ListRssLinkAndTitle;
}
}
and the method that get null is
public Cursor getAllTitles() throws SQLException
{
return db.query(DATABASE_TABLE, new String[] {
KEY_ROWID,
link,
RssTitle,
Rtl,
image
},
null,
null,
null,
null,
null
);
}
Upvotes: 0
Views: 39
Reputation: 5869
You haven't created Database Object db in your database helper class. Please make sure that you are not closing the database after inserting the Values into table.
Upvotes: 1