0

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);
jrbedard
  • 3,662
  • 5
  • 30
  • 34
NewDev
  • 9
  • 2

2 Answers2

1

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.

K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
  • java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference its show this error – NewDev Jan 14 '17 at 15:06
  • In your TextView, define an ID : `android:id="@+id/lblName"` – rupinderjeet Jan 14 '17 at 15:09
  • Yes i done that its shows this --- java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference – NewDev Jan 14 '17 at 15:09
0

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

So just right R.id before sepicifying the Id name

AshAR
  • 228
  • 1
  • 14