我正在尝试将Hashtable
作为参数传递给一个方法,该方法本身将同一个表传递给另一个方法:
public class Recruiter {
private WebDriver driver;
private DataEntry d;
private String password;
public Recruiter(WebDriver driver){
this.driver = driver;
}
public void createRecruiter(Hashtable<String, String> vars, String preferences[]){
d.enterText(vars);
driver.findElement(By.id("SAVE")).click();
}
Main:
Hashtable<String, String> vars = new Hashtable<String, String>();
vars.put("DOB","02 Mar 1983");
vars.put("SURNAME","Release");
vars.put("FIRSTNAME","David");
vars.put("COMPANYNAME","Test Inc");
Recruiter recruiter = new Recruiter(driver);
recruiter.createRecruiter(vars, preferences);
但是我在d.enterText(vars);
处得到一个空指针异常,将Hashtable
作为方法参数传递的正确方法是什么?
答案 0 :(得分:3)
我看不到你在哪里初始化d
。这导致了NPE,而不是vars
。话虽如此,d
应该在Recruiter
的构造函数中初始化。
答案 1 :(得分:0)
在使用之前初始化DataEntry d
。类似的东西:
d = new DataEntry();
在构造函数中。