Roi Amiel
Roi Amiel

Reputation: 365

Android, Cast View to TextView throw Exception

I trying to cast a viewObject to TextView object with this code:

TextView textView = (TextView) GetViewWithParams(Object);

The function "GetViewWithParams" returns viewObject. But when I run it I got this exception:

java.lang.ClassCastException: android.view.View cannot be cast to android.widget.TextView

How can I fix it?

Upvotes: 0

Views: 662

Answers (1)

Onkar Nene
Onkar Nene

Reputation: 1379

Try this -

TextView textView = (TextView) findViewById(R.id.YOUR_TEXTVIEW_ID);

Upvotes: 1

Related Questions