2

I am now trying to create new database manager under Fragment class. But unfortunately, I just stuck in the middle of some strage error that i never face with it before. Please have a look at below codes.

public class About extends Fragment {
DBManager gDatabase = new DBManager(this);
private AboutInfo ai;

The error code is that The constructor DBManage(About) is undefined. Two quick fix available:

Change constructor 'DBManager(Context) to 'DBManager(About)'' Create constructor 'DBManager(About)'

And here is my database manager codes.

public DBManager(Context context) {
    super(context, DB_NAME, null, 1);
    DBManager.myContext = context;
}

What is wrong with my codes? Any quick help would be appreciate.

myo htet aung
  • 107
  • 2
  • 12

2 Answers2

3

It needs an Activity context, not a Fragment context.

Try:

DBManager gDatabase = new DBManager(getActivity()); 
Barak
  • 16,318
  • 9
  • 52
  • 84
1

use new DBManager(this.getActivity()); but in OnCreateView or other function called after onAttach' as per Fragment lifecyle ......

Community
  • 1
  • 1
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36