1
I have this piece of code:
public class Consulta extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
try {
Socket cliente = new Socket("10.20.1.100", 12345);
ObjectInputStream entrada = new ObjectInputStream(cliente.getInputStream());
List<PessoaMOD> pessoas = (List) entrada.readObject();
for (PessoaMOD p : pessoas) {
Log.d("teste", "ID: " + p.getId() + " - Nome: " + p.getNome());
}
entrada.close();
Log.d("teste", "Conexão encerrada");
} catch (Exception e) {
Log.d("teste", "Erro: " + e);
}
return null;
}
}
private void botaoComunicarServidor() {
Button btComunicarServidor = (Button) findViewById(R.id.btComunicarServidor);
btComunicarServidor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Consulta().execute();
}
});
}
public class PessoaMOD implements Serializable{
private int id;
private String nome;
public PessoaMOD(int id, String nome){
setId(id);
setNome(nome);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}
Gives the following error:
java.lang.ClassNotFoundException: PessoaMOD
In a java application, this same code that I use on Android works...
In MANIFEST I have already released access to Internet:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
-----------------EDIT------------------
I discovered the mistake, but I don’t know how to solve... haha
The error happens because the package name of the Personal classmod on the server is different from the package name of the client application. I put the same package name and it worked. But I changed the name just to test, I can’t change the package name... How can I fix this?
He can’t turn into Personmod! You can debug to see what it returns on entry.readObject()???
– Thiago Luiz Domacoski
I found the bug, but I don’t know how to fix it... haha The error happens because the package name of the Personal classmod on the server is different from the package name of the client application. I put the same package name and it worked. But I changed the name just to test, I can’t change the package name... How can I fix this?
– Rodrigo Lima