raden rizky
raden rizky

Reputation: 21

Can not resolve int in onClick ( View view ) method

Can anyone help me resolve this issue?

public class Pin extends ActionBarActivity implements View.OnClickListener {

    Button btn_pin;
    EditText input_pin;
    int Pin;

    UserLocalStore userLocalStore;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        btn_pin = (Button) findViewById(R.id.btn_pin);
        int Pin = Integer.parseInt(input_pin.getText().toString());
        input_pin = (EditText) findViewById(R.id.input_pin);

        btn_pin.setOnClickListener(this);

        userLocalStore = new UserLocalStore(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_pin:
                int Pin = Integer.parseInt(input_pin.getText().toString());
                User user = new User(Pin);

                authenticate(user);
                break;
        }
    }

The line with int Pin has an error. I don't know how to fix this can help me?

Error:(42, 29) error: no suitable constructor found for User(int) constructor User.User(String,String) is not applicable (actual and formal argument lists differ in length) constructor User.User(String,String,int,int,String,String) is not applicable (actual and formal argument lists differ in length)

its said Error:(41, 38) error: cannot find symbol variable Pin how i can find it and make it right.?

Upvotes: 0

Views: 52

Answers (2)

Patricia
Patricia

Reputation: 2865

Error:(42, 29) error: no suitable constructor found for User(int) constructor User.User(String,String) is not applicable (actual and formal argument lists differ in length) constructor User.User(String,String,int,int,String,String) is not applicable (actual and formal argument lists differ in length)

That means that you need to change your User when you want to use an int. And you declared

int Pin;

as a global variable. Then you have to use it in the rest of your source code without the type "int". For example:

Change

int Pin = Integer.parseInt(input_pin.getText().toString());

into

  Pin = Integer.parseInt(input_pin.getText().toString());

Upvotes: 0

Hong Duan
Hong Duan

Reputation: 4294

btn_pin = (Button) findViewById(R.id.btn_pin);
int Pin = Integer.parseInt(input_pin.getText().toString());
input_pin = (EditText) findViewById(R.id.input_pin);

You should use input_pin after findViewById, or you will get a NullPointerException.

Upvotes: 1

Related Questions