0
I have a Person class with the attribute "code" type Long. I have an error in this code block. Code1 is where I got the ID.
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
pessoaSelecionada = (Pessoa) parent.getItemAtPosition(position);
codigo1.setText(pessoaSelecionada.getCodigo()); // O erro está aqui, tentei usar o Long.parseLong antes do pessoaSelecionada e não deu certo.
cnpj1.setText(pessoaSelecionada.getCnpj());
razao1.setText(pessoaSelecionada.getRazao());
latitude1.setText(pessoaSelecionada.getLatitude());
longitude1.setText(pessoaSelecionada.getLongitude());
}
});
I put this code in, compiled it without a hitch, when I open the Activity that this code is, it just closes. As if the code is with some bug. Oh when I change the Long attribute in the Person class to String and do the same as the others, it works. Only when I switch to Long does this problem happen. There would be something else that can be done?
– Matheus
@Matheus are you ever assigning a value to that attribute, even if it is zero, in your class? Because if you’re not, that could be the problem...
– g_codex
Maybe, if your question is very urgent, it is better to leave the field as String and when you need the numeral value, do the conversion to Long. Then you leave this question to be resolved when you’re calmer.
– g_codex
Did not assign any value to Long no, even because the user who will put the value, in case I have to assign anyway? It would be something like Long code = 0; ?
– Matheus
private edittext cnpj1,razao1, latitude1, longitude1,code1; So it is in my Mainactivity, as the code is caught by editText, set it along with all others.
– Matheus
p.setCodigo(Long.parseLong(code1.gettext().toString())); // I made this way to insert the data in firebase, it is inside the insertion block. What I’m having trouble with is the way and time to return this data in a listview,
– Matheus