Acitropy
Acitropy

Reputation: 113

PasswordAuthentication cannot be resolved to type Error

I am creating a class extending java.net.Authenticator to authenticate my FTP Proxy. I am getting errors when I use 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());
    }
}

I know people have used these exact lines of code before with no errors. Any idea what's wrong?

EDIT: After importing java.net.PasswordAuthentication, I'm getting an error saying that

java.net.Authenticator.getPasswordAuthentication

"overrides java.net.Authenticator.getPasswordAuthentication"

Upvotes: 0

Views: 2032

Answers (2)

Vasanthan
Vasanthan

Reputation: 13

import java.net.PasswordAuthentication;

import the passworkAuthentication class. It will work.

Upvotes: 0

ITroubs
ITroubs

Reputation: 11215

you are missing the import for the PasswordAuthentication class!!

you either use a fully referenced path like a.b.c.s.y.PasswordAuthentication instead of just PasswordAuthenticator or you include that class using an import like you did with your Authenticator class.

Upvotes: 1

Related Questions