NewDev
NewDev

Reputation: 9

no suitable method found for findViewById(TextView)

Error:(43, 35) error: no suitable method found for findViewById(TextView) method Activity.findViewById(int) is not applicable (argument mismatch; TextView cannot be converted to int) method AppCompatActivity.findViewById(int) is not applicable (argument mismatch; TextView cannot be converted to int)

Why this error occurred in this code:

 lblName = (TextView) findViewById(lblName);
 lblEmail = (TextView) findViewById(lblEmail);

Upvotes: 0

Views: 1131

Answers (2)

AshAR
AshAR

Reputation: 228

You need to write- Name = (TextView)findviewbyid(R.id.name);

So just right R.id before sepicifying the Id name

Upvotes: 0

Neerajlal K
Neerajlal K

Reputation: 6828

The argument of findViewById should be an id like R.id.id_in_xml. You are passing a variable that is already defined as TextView as an argument of findViewById, hence the error.

You should write it as follows.

lblName = (TextView) findViewById(R.id.lblName);
lblEmail = (TextView) findViewById(R.id.lblEmail);

I'm not sure of the ids, you may have to change it.

Also Make sure the id is right and the TextView exists in the xml file. If it doesn't you will run into a NullPointerException.

Upvotes: 1

Related Questions