Constructor refers to missing type context
Solution 1
What does this mean?
AFAIK, either:
You are missing the
import android.content.Context
, orYour project is messed up, and the compiler cannot find
android.content.Context
in your build path
Solution 2
In case anyone else had this issue: I had the same problem with some code that called a method from the Play Licensing library. I fixed it by using Project > Clean on Play Licensing project (as opposed to the project where the error was showing up).
Solution 3
First you should fix all other errors in your code than you should repeat Project -> Clean in Eclipse to see if the error was fixed.
Related videos on Youtube
jcw
Updated on June 29, 2022Comments
-
jcw almost 2 years
I have written a class with the following constructor
public CustomDialog(Context context)
But when I try to do this in my activity
CustomDialog diag = new CustomDialog(getApplicationContext()){/*stuff here*/};
I get the error
The constructor CustomDialog(Context) refers to the missing type Context
What does this mean? And how do I fix it?
-
jcw almost 11 yearsI can see
android.content.Context
in the imports section, what should I do to fix(or test) case 2? -
CommonsWare almost 11 years@jcw: That's difficult to answer. Whether you are building from Eclipse with ADT, or Ant, the
android.jar
for your build target should be automatically included. -
jcw almost 11 yearsOkay, well that looks sufficiently confusing. Fortunately this is a small project, so I will just copy all the classes into a new project and see if that solves the problem.
-
jcw almost 11 yearsWell, that worked..... I have no clue as to why. Accepted your answer for pushing me in the right direction.