2013-03-20 68 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類。它會工作。