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

Matthew Veid
PLUS
Matthew Veid
Courses Plus Student 666 Points

When i try to run the code i am getting the following string error

C:\Users\matt\AndroidStudioProjects\FunFacts3\app\src\main\java\com\example\funfacts\MainActivity.java:28: error: cannot find symbol string fact = "Ostriches can run faster than horses"; ^ symbol: class string

package com.example.funfacts;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView;

public class MainActivity extends AppCompatActivity { //delcare our view variables private TextView factTextView; private Button showFactButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Assign the views from the layout file to the corresponding variables make sure to not assign the views until after doing the call setcontentview
    factTextView = findViewById(R.id.facttextView2);
    showFactButton = findViewById(R.id.showfactbutton);
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //the button was clicked, so update the fact textview with a new fact
            string fact ="Ostriches can run faster than horses";
            factTextView.setText(fact);

        }
    };

1 Answer

Try changing string to String