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

activity_main cannot be resolved or is not a field

Hello, please help me i cant resolve this issue, i keep geting error: activity_main cannot be resolved or is not a field i cant get past this error, here is the syntax:

package com.zigax.crystalball2;

import android.R;
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_list_item);
        //Declare our view variables
        final TextView anwserLabel = (TextView) findViewById(R.id.text1);
        Button getAnwserButton = (Button) findViewById(R.id.button1);

        getAnwserButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                String anwser = "Yes";
                anwserLabel.setText(anwser);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

Thanks for your time and help. Ziga :D

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

I know this is an old post now, but it slipped through the cracks because it was listed as "General Discussion" instead of "Android". In case this helps you or anyone in the future:

This is an unfortunate error. I think the most common solution for me is this one: http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error (answer)

This can happen for a number of reasons. Your best bet is to look at the types of errors and where they are occurring and then matching up with one of the many solutions on StackOverflow, like this one: http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error (full question)