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

Matthew Veid
Matthew Veid
290 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

Matthew Veid
Matthew Veid
290 Points

awesome thanks man that did the trick!