Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App with Java Basic Android Programming Accessing Views in Code: Assigning Variables

Why Do We Have To Make The Classes?

I had gotten the error about the factTextView = findViewById(R.id.facttextView);

he said that he added classes and the made a new method and completely confused me. i need help please

1 Answer

Joshua Douce
Joshua Douce
13,120 Points

Hi Yoshi, You should have something like this public class mainActivity extends appCompatActivity{ // this is class for your activity

private TextView factTextView; //private member field for your textView

public void onCreate(){

factTextView = (TextView) findViewById(R.id.factTextView); // you must explicit cast the view to a text view i.e (TextView) this then sets the text view in your class to the textview you have on your layout } }

The class is a blueprint to create an object i.e a car class can create many car objects. A method is an action an instance of the object can perform for example a car can accelerate().