DHT22 always shows Error2

I update my code, but output is always Error2. I wonder if it’s hardware conection problem or others.

int main_op(){

int error =0;
float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f;
   while(1) {
      thread_sleep_for(2000);
      error = sensor.readData();
      if (0 == error) {
          c   = sensor.ReadTemperature(CELCIUS);
          f   = sensor.ReadTemperature(FARENHEIT);
          k   = sensor.ReadTemperature(KELVIN);
          h   = sensor.ReadHumidity();
          dp  = sensor.CalcdewPoint(c, h);
          dpf = sensor.CalcdewPointFast(c, h);
          printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f);
          printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf);
      } else {
          printf("Error: %d\n", error);
      }
  }

}

My library is DHT - Temp and Humidity sensor device driver. | Mbed . Plateform is MbedOS6.

Hello,

line 53 of DHT - Temp and Humidity sensor device driver. | Mbed
That probably means, it cannot establish communication with sensor. So you have wrong pin in code or connected wrong pin on board or bad sensor selected, or pull-up resistor is missing or wrong value of the resistor.

BR, Jan