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

General Discussion

My button on my android application on my emulator does not work.

On my main activity screen it keeps on giving me a red error line under my R.menu.activity_main, menu); I don't know why so can I please have help. Here is my main activity screen.

package com.example.crystalball;

import java.util.Random;

import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.TextView;

public class MainActivity extends Activity {

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

    // Declare our View variables and assign then the Views from the layout file
    final TextView answerLabel = (TextView) findViewById(R.id.textView1);
    Button getAnswerButton = (Button) findViewById(R.id.button1);


    getAnswerButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            String [] answers = {
                  "It is certain",
                  "It is decidely so",
                  "All signs point to YES",
                  "The stars are not aligned",
                  "My reply is no",
                  "It is doubtful",
                  "Better not tell you know",
                  "Concentrate and ask again",
                  "Unable to answer now" } ; 
            // The button was clicked, so update the answer label with an answer
            String answer = "";

            // Randomly select one of three answers: Yes, No, or Maybe
            Random randomGenerator = new Random(); // Construct a new Random number generator
            int randomNumber = randomGenerator.nextInt();

            /* Covert the randomNumber to a text answer
             * 0 = Yes
             * 1 = No
             * 2 = Maybe
             */

            answer = answers[randomNumber];

            // Update the label with our dynamic answer
            answerLabel.setText(answer);
        }
    });
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}