Reputation: 9
package com.reader;
import java.io.FileNotFoundException;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class feedsDB{
private static final String CREATE_TABLE_FEEDS = "create table feeds (feed_id integer primary key autoincrement, title text not null, url text not null);";
private static final String CREATE_TABLE_ARTICLES = "create table articles (article_id primary key autoincrement, feed_id text not null, title text not null, url text not null);";
private static final String FEEDS_TABLE = "feeds";
private static final String ARTICLES_TABLE ="articles";
private static final String DATABASE_NAME = "reader";
private static final int DATABASE_VERSION = 1;
private SQLiteDatabase db;
public feedsDB(Context feeder) {
try{
db=feeder.openDatabase(DATABASE_NAME, null);}
catch (FileNotFoundException e) {
try {
db = feeder.createDatabase(DATABASE_NAME, DATABASE_VERSION, 0, null);
db.execSQL(CREATE_TABLE_FEEDS);
db.execSQL(CREATE_TABLE_ARTICLES);
}
catch (FileNotFoundException e1) {
db = null;}
}
}
}
Upvotes: 0
Views: 2068
Reputation: 10239
openDatabase isn't a method on Context. It is a static method on SQLiteDatabase. Looks like you could change your code to db = SQLiteDatabase.openDatabase(...).
I would recommend reading the "Using Databases" section at this link: http://developer.android.com/guide/topics/data/data-storage.html#db. The recommended way to create a database is to extend SQLiteOpenHelper, overriding the constructor and onCreate methods.
Upvotes: 2