0
I’m trying to add dishes to my firebase database but I’m having some problems so far I don’t know why it doesn’t work. and makes this mistake:
Process: meals.com.meals, PID: 1585
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzar(Unknown Source)
at com.google.android.gms.internal.zh.zzas(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.in
For you to see what I am doing I will also post the code of the Activity and the dish class.
public class CriarPrato extends AppCompatActivity {
private Spinner NomeRestaurante;
private EditText NomePrato1;
private EditText PrecoPrato1;
private Button GerarPrato;
private String IDrestaurante;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_criar_prato);
NomeRestaurante = (Spinner) findViewById(R.id.spinnerNomeRestaurantePrato);
NomePrato1 = (EditText) findViewById(R.id.editTextNomePrato);
PrecoPrato1 = (EditText) findViewById(R.id.editTextPrecoPrato);
GerarPrato = (Button) findViewById(R.id.buttonPrato);
Query queryPrato = ConfiguracaoFirebase.getReferencia().child("Restaurante").orderByChild("localRestaurante");
queryPrato.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// final List<String> localRest = new ArrayList<String>();
final List<String> NomeRestauranteList = new ArrayList<String>();
for (DataSnapshot data : dataSnapshot.getChildren()) {
Restaurante restaurante = data.getValue(Restaurante.class);
// localRest.add(restaurante.getLocalRestaurante().toString());
NomeRestauranteList.add(restaurante.getNome().toString());
}
//LocalRestaurante = (Spinner) findViewById(R.id.SpinerLocalPrato);
// ArrayAdapter<String> areas = new ArrayAdapter<String>(getApplicationContext(), R.layout.spinner_item, localRest);
// areas.setDropDownViewResource(R.layout.spinner_item);
// LocalRestaurante.setAdapter(areas);
NomeRestaurante = (Spinner) findViewById(R.id.spinnerNomeRestaurantePrato);
ArrayAdapter<String> NomeRestAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.spinner_item, NomeRestauranteList);
NomeRestAdapter.setDropDownViewResource(R.layout.spinner_item);
NomeRestaurante.setAdapter(NomeRestAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Query query = ConfiguracaoFirebase.getReferencia().child("Restaurante").orderByChild("nome").equalTo("McDonald's");
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()) {
IDrestaurante = data.getKey();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
GerarPrato.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Prato prato = new Prato();
prato.setID(IDrestaurante);
prato.setNomePrato(NomePrato1.getText().toString());
prato.setPrecoPrato(PrecoPrato1.getText().toString());
prato.Salvar(IDrestaurante);
}
});
}
Note: I know that I am not still using the spinner, I had some problems to get the value of it so I put in hand the value, to do some tests.
public class Prato {
private String ID;
private String NomePrato;
private String PrecoPrato;
public Prato() {
}
public void Salvar(String key){
DatabaseReference reference = ConfiguracaoFirebase.getReferencia();
reference.child("Restaurante").child(key).child("Cardapio").child(getID()).setValue(this);
}
@Exclude
public String getID() {
return ID;
}
public void setID(String key) {
reference = ConfiguracaoFirebase.getReferencia().child("Restaurante").child(key).child("Cardapio");
this.ID = reference.push().getKey();
}
public String getNomePrato() {
return NomePrato;
}
public void setNomePrato(String nomePrato) {
NomePrato = nomePrato;
}
public String getPrecoPrato() {
return PrecoPrato;
}
public void setPrecoPrato(String precoPrato) {
PrecoPrato = precoPrato;
}
public DatabaseReference getReference() {
return reference;
}
public void setReference(DatabaseReference reference) {
this.reference = reference;
}
private DatabaseReference reference;
}
Follow an image of the database organization for better understanding
I want to add in each restaurant a node called Menu and within this node Menu I will put my products creating nodes With the id’s and within this is’s will have the variables: name of the dish and value on the dish.
Can you show us a Realtimedatabase firebase print on the console ? So it’s a little easier to understand the structure of your bank’s children nodes
– Eduardo Rafael Moraes
Surely I will edit and put
– IMoonBlackI
@Eduardorafaelmoraes I made the change!!! Tks
– IMoonBlackI