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) Creating the Screen Layout Adding a Button

Igor Demchenko
Igor Demchenko
1,433 Points

Error:(10, 17) Resource id cannot be an empty string (at 'id' with value '@+id/').

Error:(10, 17) Resource id cannot be an empty string (at 'id' with value '@+id/').

But, on the directory list mistake is shown in java directory, and if you follow the path and open it the three highlighted places are: (R.layout.activity_fun_fact); (R.menu.fun_fact, menu); (id == R.id.action_settings) with all three "R" highlighted in red.

Any ideas how to fix it?

5 Answers

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Are you using Eclipse or Android Studio?

If you're on Android Studio, could you try going to Build -> Clean Project After that has completed, next to Build -> Rebuild Project

Igor Demchenko
Igor Demchenko
1,433 Points

Tried, thank! But, it gets re-build with exact same mistake:

Error:(10, 17) Resource id cannot be an empty string (at 'id' with value '@+id/'). Error:(10, 17) Execution failed for task ':app:processDebugResources'.

Information:BUILD FAILED

And same path highlighted with same mistakes. Anything else I can try?

Igor Demchenko
Igor Demchenko
1,433 Points

package igordemchenko.funfact;

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

public class FunFactActivity extends Activity {

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


@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_fact, 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);
}

}

Igor Demchenko
Igor Demchenko
1,433 Points

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".FunFactActivity" android:id="@+id/">

<TextView
    android:text="Did you know?"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/factTextView"
    android:textSize="24sp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Ants stretch when they wake up in the morning."
    android:id="@+id/textView3"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:textSize="24sp" />

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Show Next Fun Fact!"
    android:id="@+id/showFactButton"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

</RelativeLayout>

Jon Kussmann
Jon Kussmann
Courses Plus Student 7,254 Points

Excellent,

In your root view, the last line says:

android:id="@+id/"

You need to have something after the 'id/'

Igor Demchenko
Igor Demchenko
1,433 Points

Thanks again for stayig with me on this one, Jon! But, as a matter of fact I dont see this portion in the the window, just hit command+A and copied. And not sure what I should have after that. Just did step-by-step after Ben's tutorial video.

Jon Kussmann
Jon Kussmann
Courses Plus Student 7,254 Points

Go ahead and use this. It's going to have some extra stuff that Ben will add in future videos, but it should be able to fix any errors that you currently have.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".FunFactsActivity"
    android:background="#ff51b46d"
    android:id="@+id/relativeLayout">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Did you know?"
        android:textSize="24sp"
        android:textColor="#80ffffff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Ants stretch when they wake up in the morning"
        android:id="@+id/factTextView"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textSize="24sp"
        android:textColor="@android:color/white" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Show Another Fun Fact"
        android:id="@+id/showFactButton"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@android:color/white"
        android:textColor="#ff51b46d" />

</RelativeLayout>
Brenton Steinmann
Brenton Steinmann
569 Points

Jon Kussmann, I had the same problem Igor had above. Which section of the your replacement XML code fixed the issue and why?

I've gone ahead and just replaced the code for now, but I'd like to understand the error a little better.

Thanks.