Reputation: 568
I'm beginner in android and call alarm manager in main activity,into the alarm manager write this code:
public class AlarmReciever extends BroadcastReceiver {
private static Context myContext;
@Override
public void onReceive(Context context, Intent intent) {
new HttpAsyncTask().execute("http://myHOST.ir/oflineValue.aspx");
}
private class HttpAsyncTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
try {
String DATABASE_NAME = "TEMPFOOD";
String TABLE_NAME = "tempData";
SQLiteDatabase db;
db=SQLiteDatabase.openOrCreateDatabase(DATABASE_NAME,myContext.MODE_PRIVATE, null);
}catch(Exception e)
{
}
}
@Override
protected void onPostExecute(String result) {
}
}
}
but in this line:
db=SQLiteDatabase.openOrCreateDatabase(DATABASE_NAME,myContext.MODE_PRIVATE, null);
why i get that error?
Upvotes: 2
Views: 200
Reputation: 184
Second Argument of openOrCreateDatabase()
must be SQLiteDatabase.CursorFactory
which is optional and it is required in order to instantiate any Cursor by default. Use the value null
as second argument, if you don't want to instantiate.
db=SQLiteDatabase.openOrCreateDatabase(DATABASE_NAME,myContext.MODE_PRIVATE, null);
If you want to instantiate, then try the below code:-
db=SQLiteDatabase.openOrCreateDatabase(DATABASE_NAME,new SQLiteDatabase.CursorFactory() {
@Override
public Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver masterQuery, String editTable, SQLiteQuery query) {
//Assign the values of masterQuery,query,editTable as per your requirements
return new SQLiteCursor(masterQuery,editTable,query);
}
}, null);
Upvotes: 0
Reputation: 543
Answer is in your question - second argument should be SQLiteDatabase.CursorFactory
Try to put null as second argument.
Upvotes: 1