首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

为啥这段代码总是报未定义哇,跪求各位大侠解释,该如何处理

2012-06-17 
为啥这段代码总是报未定义哇,跪求各位大侠解释import java.net.PasswordAuthenticationpublic class MyAu

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

热点排行