尝试在Firebase上进行更新时遇到错误,并且我不知道是否是因为未设置我的radioButtons。错误如下所示:
java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() Radio Buttom set
我需要更新请求的状态,但我不知道此错误是什么,也不知道该怎么办,以下是我编写的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pop);
//inicializar Componentes
status = findViewById(R.id.RadioGroupStatus);
alterarStatus = findViewById(R.id.buttonAlterarStatus);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int)(width*.8), (int) (height*.7));
WindowManager.LayoutParams params = getWindow().getAttributes();
params.gravity = Gravity.CENTER;
params.x = 0;
params.y = -20;
getWindow().setAttributes(params);
verificaRadioButton();
alterarStatus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
update(valoresPedido);
Toast.makeText(PopActivity.this, " Status alterado com sucesso ",
Toast.LENGTH_SHORT).show();
finish();
}
});
}
public void verificaRadioButton(){
status.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int i) {
if (i == R.id.radioButtonConfirmado){
Toast.makeText(PopActivity.this, " Status alterado para Confirmado ",
Toast.LENGTH_SHORT).show();
update(valoresPedido);
}
if (i == R.id.radioButtonPreparo){
Toast.makeText(PopActivity.this, " Status alterado para Em preparo ",
Toast.LENGTH_SHORT).show();
update(valoresPedido);
}
if (i == R.id.radioButtonSaindoEntrega){
Toast.makeText(PopActivity.this, " Status alterado para Saindo para Entrega ",
Toast.LENGTH_SHORT).show();
update(valoresPedido);
}
if (i == R.id.radioButtonRecusado){
Toast.makeText(PopActivity.this, " Status alterado para Recusado ",
Toast.LENGTH_SHORT).show();
update(valoresPedido);
}
}
});
}
public static void update(ValoresPedido v){
Map<String,Object> valoresMap = new HashMap<String,Object>();
valoresMap.put("statusPedido", v.getStatusPedido());
FirebaseConfig.getFirebase()
.child("Adega")
.child("Pedidos")
.child(pedido.getKey())
.child("ValoresPedido")
.updateChildren(valoresMap);
}
}