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

No toast showing when I run the app

So, I'm not sure why but my toast isn't showing. My code is identical to the instructors. Here it is:

package com.jackco.funfacts;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class FunFactsActivity extends AppCompatActivity {
    private FactBook factBook =  new FactBook();
    private ColorWheel colorWheel = new ColorWheel();
    //Declare our view variables
    private TextView factTextView;
    private Button showFactButton;
    private RelativeLayout relativeLayout;

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

        // Assign the views from the layout file to the corresponding variables
        factTextView = findViewById(R.id.factTextView);
        showFactButton = findViewById(R.id.showFactButton);
        relativeLayout = findViewById(R.id.relativeLayout);


        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Get fact from FactBook class
                String fact = factBook.getFact();
                int color = colorWheel.getColor();
                //Update the screen with our new fact
                factTextView.setText(fact);
                relativeLayout.setBackgroundColor(color);
                showFactButton.setTextColor(color);
            }
        };

        showFactButton.setOnClickListener(listener);

        Toast.makeText(this, "Yay! Our activity was created!", Toast.LENGTH_SHORT).show();
    }
}

Again, everything works fine, but no toast comes when I start the app. Tried closing and reopening the emulator, but that didn't work. Tried changing to LENGTH_LONG thinking I'm missing it, but that did nothing. Help?

1 Answer

I found a solution here: it worked perfectly. https://www.youtube.com/watch?v=ZK3_ib-g_no