Null Pointer Exception in Selenium WebDriver why?

public static void wait_iframe(String classname)
{
    while (! driver.findElement(By.className(classname)).isDisplayed()) {    }

    driver.switchTo().frame(driver.findElement(By.className(classname)));
}