读书人

为啥这段代码总是报未定义哇跪求各位

发布时间: 2012-06-17 21:02:01 作者: rapoo

为啥这段代码总是报未定义哇,跪求各位大侠解释
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[]类型

读书人网 >Eclipse开发

热点推荐