Android-NullPointerException:尝试在空对象引用上

时间:2019-05-08 06:33:11

标签: java android

我在运行时遇到此错误。

  

java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'boolean java.lang.String.equals(java.lang.Object)'           在com.example.smartagriculture.User.PlanActivity $ 2 $ 1.onResponse(PlanActivity.java:113)           在retrofit2.ExecutorCallAdapterFactory $ ExecutorCallbackCall $ 1 $ 1.run(ExecutorCallAdapterFactory.java:70)           在android.os.Handler.handleCallback(Handler.java:891)

这是代码

 private void DialogForm() {
    dialog = new AlertDialog.Builder(PlanActivity.this);
    inflater = getLayoutInflater();
    dialogView = inflater.inflate(R.layout.insert_serial,null);
    dialog.setView(dialogView);
    dialog.setCancelable(true);
    dialog.setTitle("Insert Serial Number");

    final EditText etSN = dialogView.findViewById(R.id.etSN);

    dialog.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            String SN = etSN.getText().toString();

            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            ApiService api = retrofit.create(ApiService.class);
            Call<Value> call = api.InsertSerial(SN,sharedPrefManager.getUsername());
            call.enqueue(new Callback<Value>() {
                @Override
                public void onResponse(Call<Value> call, Response<Value> response) {
                    String value = response.body().getValue();
                    String message = response.body().getMessage();
                    if (value.equals("1")) {
                        Toast.makeText(PlanActivity.this, message, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(PlanActivity.this, message, Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onFailure(Call<Value> call, Throwable t) {
                    Toast.makeText(PlanActivity.this, "Jaringan Error!", Toast.LENGTH_SHORT).show();
                }
            });

        }
    });


    dialog.show();
}

如何解决?

0 个答案:

没有答案