0

in widget Receiver class that extend AppWidgetProvider when i want to connect to database helper class for fetching some data by this statement i get some error:

public class wigetactivity extends AppWidgetProvider {

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {

    final DataBaseHelper myDbHelper = new DataBaseHelper(this);
         .
         .
         .
        }

i get this error: The constructor DataBaseHelper(wigetactivity) is undefined

my database helper class and constructor definition is:

public class DataBaseHelper extends SQLiteOpenHelper {
            public DataBaseHelper(Context context) {
    super(context, DB_NAME, null, 1);
    this.myContext = context;
}

 }

in a regular class that extends Activity i connect successfully to database, How i can fix that?

1
  • please post the whole stack trace and the code context when you create your helper, so we can see what this refers to Commented Mar 24, 2012 at 12:22

1 Answer 1

1

Instead of using this (which is not a Context in this case), use the provided context:

  final DataBaseHelper myDbHelper = new DataBaseHelper(context);
Sign up to request clarification or add additional context in comments.

2 Comments

what is context in this case? how i can define it?
You're getting it as a parameter: public void onUpdate(Context context, ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.