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 Blog Reader Android App Rebuilding from Scratch Creating the Project and ListActivity

I am receiving an error within the BlogReader's source file as "R cannot be resolved as a variable" what do i do?

I have just created the BlogReader app and recently updated and installed packages into eclipse through the SDK manager. I click on the error box and lists three R files that i can import (android, com.example.Blogreader, and the appcombat.v7) i dont know anything more, nor how to resolve.

2 Answers

Calvin Nix
Calvin Nix
43,828 Points

Hey,

Did you accidentally import R.Android?

If so you will probably need to remove that import and try to re-add one of your references.

This problem plagued me while I was going through the android track. Let me know if you are still getting the error.

Thanks, Calvin

If you didn't import R.Android, I found out (in Android Studio) that in the activity_main_list.xml file when deleting the padding attributes there was an empty "id=" right before the new ListView portion begins. I just deleted that cleaned and rebuilt. Below is a sample of what it should look like after its all cleaned up. Hope this helps.

<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" tools:context=".MainListActivity$PlaceholderFragment">

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@android:id/list"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

</RelativeLayout>