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 (retired 2014) Getting Started with Android Adding an OnClickListener to a Button

Syntax error on token "getAnswerButton", delete this token

I've been following the video and ran into this issue that is confusing me. I have an error when I type out getAnswerButton and I cannot continue with any of the intellisense on the other method calls.

Here is my code:

package com.example.crystalball;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

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

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

    getAnswerButton

2 Answers

What's the syntax error that you're getting? Could you hover over it and paste your syntax error here?

See my discussion subject, that is the exact error I am getting.

Oh okay, now I get it. You actually closed your onCreate() too early, that's where you variables should have been declared. So your code should look something like this in order to work:

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

    //Declare our View variables and assign them the Views from the layout file
    TextView answerLabel =  (TextView) findViewById(R.id.textView1);
    Button getAnswerButton = (Button) findViewById(R.id.button1);
    // Here comes the code :)
}

And then you should be able to use Intellisense without problems. But don't forget to do it inside the onCreate() :-)

Yep! That was the issue, thanks!

Glad to help! :-)

Hi Sako,

you can try using CTRL + Space on Windows or CMD + Space on Mac (I'm not sure about the last one) right after typing the period after "getAnswetButton". So it should look something like this "getAnswerButton." and then use CTRL + Space in order to get the content assist working. I hope this helps :)

Thanks for that, however, my getAnswerButton call still has the syntax error and intellisense won't work without clearing that error.