Constructor refers to missing type context

14,481

Solution 1

What does this mean?

AFAIK, either:

  • You are missing the import android.content.Context, or

  • Your 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.

Share:
14,481

Related videos on Youtube

jcw
Author by

jcw

Updated on June 29, 2022

Comments

  • jcw
    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
    jcw almost 11 years
    I can see android.content.Context in the imports section, what should I do to fix(or test) case 2?
  • CommonsWare
    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
    jcw almost 11 years
    Okay, 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
    jcw almost 11 years
    Well, that worked..... I have no clue as to why. Accepted your answer for pushing me in the right direction.