Trần Hữu Nhật Huy Trần Hữu Nhật Huy - 3 years ago 84
Android Question

OnClickListener Error?

I'm building a program using some buttons. Everything is perfect and beautiful until this error popped up.

onclicklistener error

I tried as much ways as possible but it still doesn't work! Can you explain the error and the way to fix it? Thanks for your help! <3
Here is my code:

package com.huy9515gmail.mycontact;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {
@BindView( EditText edtName;
@BindView( Button btnAdd;
@BindView( EditText edtNumber;
@BindView( RadioButton rdbtn_male;
@BindView( RadioButton rdbtn_female;
@BindView( RadioButton rdbtn_others;
@BindView( RadioGroup genderSelection;
private ListView lvContact;

protected void onCreate(Bundle savedInstanceState) {

lvContact = (ListView) findViewById(;
final ArrayList<Contact> arrContact = new ArrayList<>();

btnAdd.setOnClickListener(new View.OnClickListener() {
public void onclick(View v) {
//validating contact info
if (((edtName.getText().toString().trim()) == "") || (edtNumber.getText().toString().trim() == "")) {
Toast.makeText(MainActivity.this, "Invalid contact info! Please try again!", Toast.LENGTH_SHORT).show();
//adding contact info
else {
Contact contact = new Contact(Gender.male, "", "");

//receiving gender
boolean isMale, isFemale, isOthers;
if (rdbtn_male.isChecked()) contact.setGender(Gender.male);
if (rdbtn_female.isChecked()) contact.setGender(Gender.female);
if (rdbtn_others.isChecked()) contact.setGender(Gender.others);

//adding info


CustomAdapter customAdapter = new CustomAdapter(this, R.layout.row_listview, arrContact);

Answer Source

Replace this line:

public void onclick(View v) {

With this (we just modified the capital C):

public void onClick(View v) {

It is a tricky thing, but since you're working with anonymous classes, you need to override the exact signature that the interface is giving you, and it's case-sensitive.

The implementation of the View.OnClickListener interface, requires you to implement the onClick method which receives one argument of type View.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download