0
The error occurs when I add the long type attribute, with the String type does not give error, I can insert in the database but gives error in the getvalue
.
Follows the code
package com.mycompany.parcelasdecartao;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import com.firebase.client.*;
import com.mycompany.parcelasdecartao.model.*;
import java.util.*;
public class CadastrarParcelaActivity extends Activity
{
private EditText editTextNumParcelas;
private EditText editTextDescricao;
private EditText editTextValor;
private EditText editTextDataCompra;
private Button buttonSave;
//CRIA POPUP COM O CALENDÁRIO
DatePickerDialog datePickerDialogDataNascimento;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cadastrar_parcela);
Firebase.setAndroidContext(this);
/*CARREGA O MÉTODO DE CRIAÇÃO DOS COMPONENTES*/
this.CriarComponentes();
this.CriarEventos();
}
//VINCULA O COMPONENTE DA NOSSA TELA AO OBJETO DA NOSSA ATIVIDADE
protected void CriarComponentes(){
//VINCULANDO A LISTA DA TELA AO LISTVIEW QUE DECLARAMOS
buttonSave = (Button) findViewById(R.id.buttonSave);
editTextNumParcelas = (EditText) findViewById(R.id.editTextNumParcelas);
editTextValor = (EditText) findViewById(R.id.editTextValCompra);
editTextDataCompra = (EditText) findViewById(R.id.editTextDatCompra);
editTextDescricao = (EditText) findViewById(R.id.editTextDescCompra);
}
//CRIA EVENTO PARA A LISTA
protected void CriarEventos(){
final Calendar calendarDataAtual = Calendar.getInstance();
int anoAtual = calendarDataAtual.get(Calendar.YEAR);
int mesAtual = calendarDataAtual.get(Calendar.MONTH);
int diaAtual = calendarDataAtual.get(Calendar.DAY_OF_MONTH);
//MONTANDO O OBJETO DE DATA PARA PREENCHER O CAMPOS QUANDO FOR SELECIONADO
//FORMATO DD/MM/YYYY
datePickerDialogDataNascimento = new DatePickerDialog(this,new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int anoSelecionado, int mesSelecionado, int diaSelecionado) {
//FORMATANDO O MÊS COM DOIS DÍGITOS
String mes = (String.valueOf((mesSelecionado + 1)).length() == 1 ? "0" + (mesSelecionado + 1 ): String.valueOf(mesSelecionado));
editTextDataCompra.setText(diaSelecionado + "/" + mes + "/" + anoSelecionado);
}
}, anoAtual, mesAtual, diaAtual);
//CRIANDO EVENTO NO CAMPO DE DATA PARA ABRIR A POPUP
editTextDataCompra.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
datePickerDialogDataNascimento.show();
}
});
//CRIANDO EVENTO NO CAMPO DE DATA PARA ABRIR A POPUP
editTextDataCompra.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
datePickerDialogDataNascimento.show();
}
});
buttonSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View p1)
{
// TODO: Implement this method
String parcelaId;
String caminho = "/Compras";
//Creating firebase object
Firebase ref = new Firebase(Config.FIREBASE_URL + caminho);
//desabiltando o botao pata evitsr dula entras
buttonSave.setEnabled(false);
//novo objeto parcelas
ParcelaCartao parcela = new ParcelaCartao();
long num_parcelas = Long.parseLong(editTextNumParcelas.getText().toString());
parcela.setNumparcelas(num_parcelas);
parcela.setDescricao(editTextDescricao.getText().toString().trim());
parcelaId = ref.push().getKey();
ref.child(parcelaId).setValue(parcela);
ref.child(parcelaId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
//habilitando o botao pata evitsr dula entras
buttonSave.setEnabled(true);
ParcelaCartao parcela = new ParcelaCartao();
ArrayList<ParcelaCartao> array = new ArrayList<>();
for (DataSnapshot childSnapshot : snapshot.getChildren())
{
parcela = childSnapshot.getValue(ParcelaCartao.class);
array.add(parcela);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
}); }
}); }
}
Follow the Json
{
"-KvlDeyP0v8O76tUnuKW" : {
"descricao" : "teste com long",
"numparcelas" : 5
},
"-KvmwSsqnPir51cPi6NJ" : {
"descricao" : "teste tarde",
"numparcelas" : 5
},
"-KvrFqmHHzD0SkOguotR" : {
"descricao" : "teste sabado",
"numparcelas" : 6
}
}
Follows the class
import com.google.firebase.database.*;
/**
* Created by Belal on 2/23/2016.
*/
@IgnoreExtraProperties
public class ParcelaCartao
{
private String descricao;
private long numparcelas;
public ParcelaCartao(String descricao, long numparcelas ){
setDescricao(descricao);
setNumparcelas(numparcelas);
}
public ParcelaCartao() {
/*Blank default constructor essential for Firebase*/
}
public String getDescricao()
{
return descricao;
}
public void setDescricao(String descricao)
{
this.descricao = descricao;
}
public Long getNumparcelas()
{
return numparcelas;
}
public void setNumparcelas(long numparcelas)
{
this.numparcelas = numparcelas;
}
@Override
public String toString() {
return "Compra: " + descricao +
"\n num_parcelas: " + numparcelas;
}
}
Follow the error
07 11:45:09.745 21664 21664 ANDROHIDROUNTIME FATAL EXCEPTION: main 10-07 11:45:09.745 21664 21664 Androhidrountime Process: com.mycompany.parcelasdecartao, PID: 21664 10-07 11:45:09.745 21664 21664 E AndroidRuntime com.firebase.client.Firebaseexception: Failed to Bounce to type 10-07 11:45:09.745 21664 21664 Androidruntime at com.firebase.client.DataSnapshot.getValue(Datasnapshot.java:185) 10-07 11:45:09.745 21664 21664 Androidruntime at com.mycompany.parcelasdecartao.Cadastrarparcelaactivity$100000004$100000003$0$debug.onDataChange(Cadastrarparcelaactivity.java:169) 10-07 11:45:09.745 21664 21664 Androidruntime at com.mycompany.parcelasdecartao.Cadastrarparcelaactivity$100000004$100000003.onDataChange(Cadastrarparcelaactivity.java) 10-07 11:45:09.745 21664 21664 Androidruntime at com.firebase.client.core.Valueeventregistration.fireEvent(Valueeventregistration.java:45) 10-07 11:45:09.745 21664 21664 Androidruntime at com.firebase.client.core.view.DataEvent.fire(Dataevent.java:45) 10-07 11:45:09.745 21664 21664 Androidruntime at com.firebase.client.core.view.Eventraiser$1.run(Eventraiser.java:38) 10-07 11:45:09.745 21664 21664 Androidruntime at android.os.Handler.handleCallback(Handler.java:746) 10-07 11:45:09.745 21664 21664 And Androidruntime at android.os.Handler.dispatchMessage(Handler.java:95) 10-07 11:45:09.745 21664 21664 And Androidruntime at android.os.Looper.loop(Looper.java:148) 10-07 11:45:09.745 21664 21664 And Androidruntime at android.app.Activitythread.main(Activitythread.java:5443) 10-07 11:45:09.745 21664 21664 Androidruntime at java.lang.reflect.Method.invoke(Native Method) 10-07 11:45:09.745 21664 21664 And Androidruntime at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:728) 10-07 11:45:09.745 21664 21664 Androidruntime at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:618) 10-07 11:45:09.745 21664 21664 Androhidrountime Caused by: com.fasterxml.Jackson.databind.Jsonmappingexception: Can not instantiate value of type [simple type, class com.mycompany.parcelasdecartao.model.Parcelacartao] from String value; no single-string constructor/Factory method 10-07 11:45:09.745 21664 21664 E Androidruntime at com.fasterxml.Jackson.databind.deser.std.Stdvalueinstantiator. _createFromStringFallbacks(Stdvalueinstantiator.java:428) 10-07 11:45:09.745 21664 21664 Androidruntime at com.fasterxml.Jackson.databind.deser.std.Stdvalueinstantiator.createFromString(Stdvalueinstantiator.java:299) 10-07 11:45:09.745 21664 21664 Androidruntime at com.fasterxml.Jackson.databind.deser.BeanDeserializerBase.deserializeFromString(Beandeserializerbase.java:1056) 10-07 11:45:09.745 21664 21664 Androidruntime at com.fasterxml.Jackson.databind.deser.BeanDeserializer. _deserializeOther(Beandeserializer.java:136) 10-07 11:45:09.745 21664 21664 Androidruntime at com.fasterxml.Jackson.databind.deser.BeanDeserializer.deserialize(Beandeserializer.java:123) 10-07 11:45:09.745 21664 21664 Androidruntime at com.fasterxml.Jackson.databind.Objectmapper. _readMapAndClose(Objectmapper.java:2888) 10-07 11:45:09.745 21664 21664 Androidruntime at com.fasterxml.Jackson.databind.Objectmapper.readValue(Objectmapper.java:2034) 10-07 11:45:09.745 21664 21664 Androidruntime at com.firebase.client.DataSnapshot.getValue(Datasnapshot.java:183) 10-07 11:45:09.745 21664 21664 Androidruntime ... 12 more
Here it worked normally. Are you sure your bank is exactly like this?
– Pablo Almeida
Hello Pablo, thank you for helping me. I entered the complete code, who knows you find the error . About the database I posted an image of the firebase console.
– UltraSeven
I use AIDE as a tool for development. Did it get junk somewhere that is generating this error? I’m thinking of just using string or rewriting the project from scratch. Thank you.
– UltraSeven