0

How does ist come that c and today is not visible in fetchingData() ? I get a NullPointer-Exception when running the code in main-class :/ Thanks for any help!

public class InputData {

    Calendar c;
    Date today;

    String DATE_FORMAT = "MM/dd/yyyy";
    SimpleDateFormat sdf;

    Double[][] hPrice;
    Double[][] qhPrice;
    Double[][] qhEua;
    Double[][] qhGas;
    Integer[][] qhTemperature;
    Integer[][] qhAirpressure;

    Date[][] qhDate; // may be useful some day
    Date[][] qhWeatherDate; // may be useful some day

    public InputData() {
        Calendar c = Calendar.getInstance();
        Date today = new Date();
        today = c.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        System.out.println(sdf.format(today));
    }

    public void startFetching() {
        // +++ Access-Import EUA's +++
        Access aQuery = new Access();
        c.add(Calendar.DATE, -1);
        today = c.getTime();
        aQuery.eua(sdf.format(today));
Andrew
  • 67
  • 8

1 Answers1

3

You save the objects in local variables and don't use the class members. Change your code:

  public InputData() {
        this.c = Calendar.getInstance();
        this.today = new Date();
        today = c.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        System.out.println(sdf.format(today));
    }
Markus
  • 1,141
  • 1
  • 9
  • 25