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 (retired 2014) Getting Started with Android Initial Layout

Akshay Shivpuri
Akshay Shivpuri
2,917 Points

Error in mainactivity.java after deleting framelayout.xml

Receiving error in this line

if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }

Error states

Multiple markers at this line
    - container cannot be resolved or is not a field
    - The method add(Fragment, String) in the type FragmentTransaction is not applicable for the arguments (Fragment, 
     MainActivity.PlaceholderFragment)

1 Answer

When you modify (or add/delete) layout files, your R class gets regenerated. Chances are R.id.container no longer exists. Your current layout needs to have an element in your current layout with the property android:id="@+id/container"