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
Jake Nisenboim
3,374 PointsAndroid Studio Bug
So I made a new project, didn't change anything in the .java file and its giving me an error message. This is my code (unchanged)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
It is this line that supposedly has the problem:
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
2 Answers
Ozhan Saat
Courses Plus Student 4,002 PointsIt's looking for something in the XML which isn't there. I'm going to guess you removed some stuff. Just delete that section of code and the error will go away.
Jake Nisenboim
3,374 PointsI did not change or delete anything in the XML file, I literally just created the project. If I delete that line of code, 31 other errors are present in the rest of the .java file after that line that was deleted.
Charlotte Glasson
4,191 PointsJake did you solve this? Im getting the exact same error right now!
Jake Nisenboim
3,374 PointsJake Nisenboim
3,374 PointsSpecifically (R.id.fab)
"cannot resolve symbol 'fab'