2013-03-20 70 views
0

我正在创建一个扩展java.net.Authenticator来验证我的FTP代理的类。我得到的错误,当我使用的PasswordAuthentication ...无法解析PasswordAuthentication以键入错误

import java.net.Authenticator; 
import java.net.PasswordAuthentication; 
class ProxyAuthenticator extends Authenticator { 
    private String user, password; 
    public ProxyAuthenticator(String user, String password) { 
     this.user = user; 
     this.password = password; 
    } 
    //error here 
    public PasswordAuthentication getPasswordAuthentication() { 
     return new PasswordAuthentication(user, password.toCharArray()); 
    } 
} 

我知道前使用这些代码确切行没有任何错误。任何想法有什么不对?

编辑:进口java.net.PasswordAuthentication后,我收到一个错误,指出

java.net.Authenticator.getPasswordAuthentication

“覆盖java.net.Authenticator.getPasswordAuthentication”

回答

1

您错过了PasswordAuthentication课程的导入!

你要么使用像a.b.c.s.y.PasswordAuthentication,而不是仅仅PasswordAuthenticator完全参考路径,也喜欢你和你的Authenticator阶级都使用进口包括类。

+0

谢谢,但现在我得到一个错误说...“覆盖java.net.Authenticator.getPasswordAuthentication” – Acitropy 2013-03-20 17:12:25

+0

这不是整个错误 – ITroubs 2013-03-20 17:13:31

+0

这就是它至少说在Eclipse中。 – Acitropy 2013-03-20 17:17:50

0
import java.net.PasswordAuthentication; 

进口passworkAuthentication类。它会工作。