So I have been going through the Android Developer training on the official site and there is a point where they want us to finally instantiate our database.
So they tell us to use this snippet of code:
FeedReaderDbHelper mDbHelper = new FeedReaderDbHelper(getContext());
However, I'm getting an error for the getContext()
method. It states that it cannot find a symbol for that method.
So I searched the source and that method in the View class just cannot be found. Is this a deprecated method? And if this isn't an option, is there any other way we can grab the context of a view?
Thank you!
getContext() method returns a drawing context on the canvas, or null if the context identifier is not supported, or the canvas has already been set to a different context mode.
The HTMLCanvasElement interface provides properties and methods for manipulating the layout and presentation of <canvas> elements. The HTMLCanvasElement interface also inherits the properties and methods of the HTMLElement interface.
The line of code you pass is:
FeedReaderDbHelper mDbHelper = new FeedReaderDbHelper(geContext());
It should work if you substitute for any of these code lines :
FeedReaderDbHelper mDbHelper = new FeedReaderDbHelper(getContext());
Or
FeedReaderDbHelper mDbHelper = new FeedReaderDbHelper(getApplicationContext());
Or
FeedReaderDbHelper mDbHelper = new FeedReaderDbHelper(this);
The android developer documentation of the Context:
https://developer.android.com/reference/android/content/Context.html
You might found helpful too look in this question, that explains what is Context for:
What is 'Context' on Android?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With