Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (2014) Basic Android Programming Adding the onClick() Method

Josue Castaneda
Josue Castaneda
360 Points

Problems running app

When I run the app I get 6 errors which are the following:

Error:(18, 14) error: cannot find symbol class Textview Error:(18, 36) error: cannot find symbol class TextView Error:(19, 9) error: cannot find symbol class Button Error:(19, 34) error: cannot find symbol class Button Error:(24, 17) error: cannot find symbol class string

MY CODE CAN BE FOUND BELOW WHICH IS THE SAME ONE AS THE ONE IN THE VIDEO

// protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fun_facts);

    //declare our view variables and assign them the views from the layout file
   final Textview factLabel = (TextView) findViewById(R.id.factTextView);
    Button showFactButton = (Button) findViewById(R.id.showFactButton);
    View.OnClickListener Listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //the button was clicked so update the fact label with a new fact
            string fact = "ostriches can run faster than horses.";
            factLabel.setText(fact);

        }
    };
    showFactButton.setOnClickListener(Listener);

//

Zuhayr Elahi
Zuhayr Elahi
2,582 Points

Do you have the xml file as well? It would help us figure out more information regarding the issue

2 Answers

Niyamat Almass
Niyamat Almass
8,176 Points

I don't know what is your problem is but try that

if you are using windows Go to - On the main menu, choose File | Invalidate Caches/Restart. The Invalidate Caches message appears informing you that the caches will be invalidated and rebuilt on the next start. Use buttons in the dialog to invalidate caches, restart IntelliJ IDEA or both.

if you are using mac Go to - On the main menu, choose Android Studio | Invalidate Caches/Restart. The Invalidate Caches message appears informing you that the caches will be invalidated and rebuilt on the next start. Use buttons in the dialog to invalidate caches, restart IntelliJ IDEA or both.

Adam Ebeid
Adam Ebeid
3,240 Points

You need to import the following classes:

import android.widget.Button; import android.widget.TextView;