java.lang.NumberFormatException: Invalid int: "null"

0

Good day, Can someone help me solve this error? Using Firebase Database on Android with the structure so

and this code

    Bundle bundle = getIntent().getExtras();
    if(bundle !=null) {
        usuari = bundle.getString("x");
        dos = bundle.getString("d");
    }

    ver2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            vista.setText("Dosis Ingresada: "+dos+"mg/dl");
            Time today=new Time(Time.getCurrentTimezone());
            today.setToNow();
            int dia=today.monthDay;
            int mes=today.month;
            int ano=today.year;
            mes=mes+1;
            verf.setText("Mes : "+ mes +" " +"Dia : " + dia + " " + "Año : " + ano);
            String usuario=usuari;
            String midosis=dos;
            String id=my.push().getKey();
            final Usuario user = new Usuario(usuario,midosis,id,mes,dia,ano);
            my.child("dosis").child(id).setValue(user);
            calcularMayorDosis();
            Button boton=(Button)v;
            boton.setEnabled(false);
        }

    });



    salir.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(Hitorial.this, MainActivity.class));
        }
    });



}

private void calcularMayorDosis(){


    my.child("dosis").orderByKey().limitToLast(3).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            if(dataSnapshot.exists()){
                ArrayList<String> dosis = new ArrayList();
                for(DataSnapshot snapshot : dataSnapshot.getChildren()) {
                    Usuario us = snapshot.getValue(Usuario.class);
                    dosis.add(us.getDosis());
                    Log.e("Datos: " , "" + us.getDosis());
                }
                String valor1 = dosis.get(0);
                String valor2 = dosis.get(1);
                String valor3 = dosis.get(2);
                textViewant.setText("Dosis anterior: "+valor2+" md/dl");

                int valorDosis1 = Integer.parseInt(valor1);
                int valorDosis2 = Integer.parseInt(valor2);
                int valorDosis3 = Integer.parseInt(valor3);
                Log.e(TAG, ""+valorDosis1+""+valorDosis2+""+valorDosis3);

                int a,b,c;
                a=0;
                b=0;
                c=0;

                if(valorDosis1>=130){
                    a=1;
                }
                if(valorDosis2>=130){
                    b = 1;
                }
                if(valorDosis3>=130){
                    c=1;
                }
                int suma = a+b+c;
                if(suma == 1){
                    textViewcalculo.setText("*Mantiene la dosis de ayer*");

....

I get the following error

On the line

int valorDosis2 = Integer.parseInt(valor2);

And I do not know why it was ok now, it does not save me or call me from a database and Asi appears and the app stops

    
asked by Julian 25.10.2018 в 21:33
source

0 answers