I am sending information from my android application to my database by php, however when I execute it and with a spinner I select some of the available options and I give it the following results, I tried to fix it but always says that, I dont know what to do, please help!
2020-06-30 08:50:48.688 19172-19330/com.example.tallerof E/Volley: [40176] NetworkDispatcher.processRequest: Unhandled exception java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
Here the class where I put everything to send it to php
package com.example.tallerof;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.util.HashMap;
import java.util.Map;
public class Aceptado extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
String valor;
String rol;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_aceptado);
Spinner snipper= findViewById(R.id.spi);
Button ir= findViewById(R.id.button10);
ArrayAdapter<CharSequence> adapter= ArrayAdapter.createFromResource(this, R.array.Estatus, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
snipper.setAdapter(adapter);
snipper.setOnItemSelectedListener(this);
valor = getIntent().getStringExtra("matricula");
ir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
servicio("https://tallerof.000webhostapp.com/Actualiza.php");
}
});
}
private void servicio(String URL){
StringRequest stringRequest= new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getApplicationContext(), "Listo", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Aceptado.this, MainActivity2.class);
startActivity(intent);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),error.toString(),Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> parametros= new HashMap<String,String>();
parametros.put("Id_nuevo",rol);
parametros.put("Aceptado","1");
parametros.put("Matricula_Nuevo",valor);
return parametros;
}
};
RequestQueue requestQueue= Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String text= parent.getItemAtPosition(position).toString();
if(text.equals("Alumno")){
rol="1";
}
if(text.equals("Maestro")){
rol="2";
}
if(text.equals("Administracion")){
rol="3";
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
The problem was that I was passing variables incorrectly with the intent