E/Volley: [40176] NetworkDispatcher.processRequest: 未处理的异常 java.lang.NullPointerException
E/Volley: [40176] NetworkDispatcher.processRequest: Unhandled exception java.lang.NullPointerException
我正在通过 php 从我的 android 应用程序向我的数据库发送信息,但是当我执行它并使用微调器时,我 select 一些可用的选项,我给它出现以下结果,我试图修复它但总是说,我不知道该怎么做,请帮忙!
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
这里是class,我把所有的东西都寄给了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) {
}
}
问题是我按意图错误地传递了变量
我正在通过 php 从我的 android 应用程序向我的数据库发送信息,但是当我执行它并使用微调器时,我 select 一些可用的选项,我给它出现以下结果,我试图修复它但总是说,我不知道该怎么做,请帮忙!
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
这里是class,我把所有的东西都寄给了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) {
}
}
问题是我按意图错误地传递了变量