import java.net.PasswordAuthentication;
public class MyAuthenticator {
String userName = null;
String password = null;
public MyAuthenticator()
{
}
public MyAuthenticator(String username,String pwd)
{
this.userName = username;
this.password = pwd;
}
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(userName, password);
}
}
求教各位大侠,为啥
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(userName, password);
}
这一段代码总是报错,The constructor PasswordAuthentication(String, String) is undefined
------解决方案--------------------
jdk中,PasswordAuthentication类的构造方法是:
PasswordAuthentication(String userName, char[] password)
而不是
PasswordAuthentication(String userName, String password)
------解决方案--------------------
可以先对password调用toCharArray(),转化为char[]类型