Autenticação de email - (Resolvido)

3 respostas
DAREK6920

Por favor gente, se alguem puder me ajudar, agradeço de montão.
O que tem de errado neste codigo ?

import java.net.Authenticator;
import java.net.PasswordAuthentication;

/**
 *
 * @author Dario
 */
public class Autenticacao extends Authenticator{
  protected PasswordAuthentication
  			getPasswordAuthentication() {

  System.out.println("Autenticando...");
  return new PasswordAuthentication("usuario","senha");
  }   
}

A linha do return fica vermelha e informa o seguinte :

constructor PasswordAuthentication in class java.net.PasswordAuthentication cannot be applied to given types;
required: java.lang.String,char[]
found: java.lang.String,java.lang.String
reason: actual argument java.lang.String cannot be converted to char[] by method invocation conversion
----

3 Respostas

guilherme.dio

Esta errado porque o segundo parametro do construtor pede um array de caracteres, então faça o seguinte que funcionará:

import java.net.Authenticator;  
import java.net.PasswordAuthentication;  
  
/** 
* 
* @author Dario 
*/  
public class Autenticacao extends Authenticator{  
  protected PasswordAuthentication  
            getPasswordAuthentication() {  
  
  System.out.println("Autenticando...");  
  return new PasswordAuthentication("usuario","senha".toCharArray());  
  }     
}
T

estava com o mesmo problema e como o amigo guilherme.dio disse fiz e a linha do return (13) ficou ok.
agora a linha 09 esta vermelha com o seguinte texto

getPasswordAuthentication() in <anonymous testin.Carregando$1> cannot override getPasswordAuthentication() in Authenticator
return type java.net.PasswordAuthentication is not compatible with javax.mail.PasswordAuthentication

alguem poderia me ajudar?

T

tibum:
estava com o mesmo problema e como o amigo guilherme.dio disse fiz e a linha do return (13) ficou ok.
agora a linha 09 esta vermelha com o seguinte texto

getPasswordAuthentication() in <anonymous testin.Carregando$1> cannot override getPasswordAuthentication() in Authenticator
return type java.net.PasswordAuthentication is not compatible with javax.mail.PasswordAuthentication

alguem poderia me ajudar?

problema resolvido… tava importando uma biblioteca errada… afff

Criado 29 de agosto de 2012
Ultima resposta 2 de out. de 2012
Respostas 3
Participantes 3