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 Build a Simple Android App (2014) Getting Started with Android Running the Fun Facts Project

Samuel Diaz
Samuel Diaz
2,814 Points

error: package R does not exist

When I try to run the program, I get the error; error package R does not exist. I don't know why I get this error.

Stone Preston
Stone Preston
42,016 Points

can you post your code

Samuel Diaz
Samuel Diaz
2,814 Points

import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem;

public class FunFactsActivity extends Activity {

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


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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

I didn't edit the code at all, Everywhere that an 'R' appears is highlighted in red.

2 Answers

Stone Preston
Stone Preston
42,016 Points

hmm. and you havent added any code at this point correct? this is a completely fresh project? try invalidating your cache by going to file -> invalidate cache. it will restart android studio. try running again after that

Samuel Diaz
Samuel Diaz
2,814 Points

Yes, it was completely new, thanks for the help, the program runs fine now

Stone Preston
Stone Preston
42,016 Points

awesome glad its working