Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getContext() doesn't exist

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!

like image 756
LalienX Avatar asked Aug 30 '14 22:08

LalienX


People also ask

What is the getContext function?

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.

What is HTMLCanvasElement?

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.


1 Answers

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?

like image 64
lcsvcn Avatar answered Sep 28 '22 03:09

lcsvcn