Error with class TimePickerDialoG: Can not resolve constructor 'TimePickerDialog (android.content.context, int, int, boolean)'

1

Having the following code, I have solved a problem.

app class

import android.app.Application;
import android.content.Context;

public class App extends Application {

    private static Application myApplication;

    public static Application getApplication() {
        Application sApplication = new Application();
        return sApplication;
    }

    public static Context getContext() {
        return getApplication().getApplicationContext();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        myApplication = this;
    }
}  

newInstance within snippet.

   public static Categories newInstance(int index,CheckBox check) {
    Categories categories = new Categories();
    java.util.Calendar now = java.util.Calendar.getInstance();

    TimePickerDialog tpd = new TimePickerDialog(
            App.getContext(),
            now.get(java.util.Calendar.HOUR_OF_DAY),
            now.get(java.util.Calendar.MINUTE),
            check.isChecked()


    );

But now I have the disadvantage that when I call the App.getContext () context in this way when passing the parameters, it shows me the following error:

Can not resolve constructor 'TimePickerDialog (android.content.context, int, int, boolean)'

EYE I call it this way because if I use this, getContext () or Categories.this tells me that you can not reference a context within a static method.

    
asked by Eduardo Jesus 22.06.2016 в 02:38
source

1 answer

0

By viewing the TimePickerDialog documentation you can see that effectively there is no constructor that accepts those arguments. There are two constructors for this class:

TimePickerDialog(Context, TimePickerDialog.OnTimeSetListener, int, int, boolean)

TimePickerDialog(Context, int, TimePickerDialog.OnTimeSetListener, int, int, boolean)

Apparently, you want to use the first constructor, for which you would be missing the argument of type TimePickerDialog.OnTimeSetListener . Add this argument and your code can compile.

    
answered by 22.06.2016 / 02:57
source