boa noite pessoal, to aqui tentando criar um aplicativo para atualizar um programa do tipo cliente servidor, mas quando passo os dados de um metodo para a o objeto que criei o java me retorna um erro como se fosse nul, se alguem puder me dizer ai onde que errei … vlw
public class Servidor {
String dominio ;
String ip ;
String tipo;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
Servidor Loja = recebeDados();
Hashtable authEnv = new Hashtable(11);
authEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
authEnv.put(Context.PROVIDER_URL,"ldpa://"+Loja.dominio+":389 ");
authEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
authEnv.put(Context.SECURITY_PRINCIPAL, "administrador@"+Loja.dominio);
authEnv.put(Context.SECURITY_CREDENTIALS, "xxx"+Loja.ip+"x");
System.out.println("Dominio: "+Loja.dominio);
}
private static Servidor recebeDados(Servidor loja) throws FileNotFoundException, IOException {
Map<String, String> tags = new HashMap<String, String>();
File arquivo = new File("C:/caminho/conf.xml");
BufferedReader reader = new BufferedReader(new FileReader(arquivo));
String line = "";
int inicio = 0;
int fim = 0;
while((line = reader.readLine()) != null){
if(line.startsWith("<dominio>")){
inicio = "<dominio>".length();
fim = (line.length()-1) - "</dominio>".length();
tags.put("dominio", line.substring(inicio, fim));
loja.dominio =tags.get("dominio");
}
else{
if(line.startsWith("<ip>")){
inicio = "<ip>".length();
fim = (line.length()-1) - "</ip>".length();
tags.put("ip", line.substring(inicio, fim));
loja.ip=tags.get("ip");
}
else{
if(line.startsWith("<tipo>")){
inicio = "<tipo>".length();
fim = (line.length()-1) - "</tipo>".length();
tags.put("tipo", line.substring(inicio, fim));
loja.tipo = tags.get("tipo");
}
}
}
}
return loja;
}
}
so que quando executo o systema me retorna a seguinte messagem
Exception in thread “main” java.lang.NullPointerException
at sav.Main.recebeDados(Main.java:52)
at sav.Main.main(Main.java:28)
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 3 segundos)
a linha 52 a qual o erro se refere e a
loja.dominio =tags.get("dominio");