-2

For some reason my app is keep coming up with this error. I have added the error log below but cannot work out what the problem is. I have tried many times to figure it out but still not getting anywhere. Hopefully you can understand the error log.

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at .....buildaempiredesign.GameRegister.onCreate(GameRegister.java:34)

The code for that is the bRegister.setOnClickListener section of code below.

            bRegister.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                final String email = etEmail.getText().toString();
                final String password = etPassword.getText().toString();
                @SuppressLint("SimpleDateFormat") final String birthday = new SimpleDateFormat("dd/MM/yyyy").format(etBirthday.getText().toString());
                final String playername = etPersonName.getText().toString();
                final String gender = etPersonName.getText().toString();
                final String gamename = etGameName.getText().toString();

                Response.Listener<String> responceListener = new Response.Listener<String>(){
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonResponce = new JSONObject(response);
                            boolean error = jsonResponce.getBoolean("error");

                            if (!error){
                                Intent intent = new Intent(GameRegister.this, GameLogin.class);
                                GameRegister.this.startActivity(intent);
                            } else {
                                AlertDialog.Builder builder = new AlertDialog.Builder(GameRegister.this);
                                builder.setMessage("Login Failed")
                                        .setNegativeButton("Retry", null)
                                        .create()
                                        .show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                };

                RegisterRequest registerRequest = new RegisterRequest(email, password, playername, gender, birthday, gamename, responceListener);
                queue.add(registerRequest);
            }
        });
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
tom
  • 1
  • 5

1 Answers1

0

where is your Code at line 34? makesure you have initialized your Button. and your button id is not wrong.

Button bRegister;

or Button bRegister = (Button)findViewById(R.id.yourbuttonid);

AufaDhiya
  • 21
  • 2
  • 7