Reputation: 59
I must declare the following variable in a class extending Fragment:
public class CarrelloFragment extends Fragment {
DatabaseHelper sqLite=new DatabaseHelper(this); //here is the error
The constructor of DatabaseHelper class does not allow to do this with a fragment.
Here is the code of the constructor of DatabaseHelper class that extends SQLiteOpenHelper:
public class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "MySupermarket.db";
private static final int SCHEMA_VERSION = 2;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, SCHEMA_VERSION);
}
Is there a way to declare a DatabaseHelper variable inside the fragment class?
Upvotes: 0
Views: 434
Reputation: 6245
try DatabaseHelper sqLite=new DatabaseHelper(getActivity());
Upvotes: 2