4 Replies - 5799 Views - Last Post: 06 August 2012 - 07:24 AM

#1 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

R.id not found

Posted 05 August 2012 - 08:17 PM

Hello everyone, I'm fairly new to Android development with Eclipse, and I'm reading a book on it, but for some reason, when using the findViewByid() method, and the parameter should be something like R.id.myButton. An error message comes up over the id part saying "id cannot be resolved or is not a field". So, I'm not sure if something has been changed since the book I'm reading was published, or what. But this doesn't seem to work, do I need to do something to create the R.id? Because I don't see it in the gen folder. Help would be greatly appreciated. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: R.id not found

#2 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: R.id not found

Posted 05 August 2012 - 08:36 PM

Ok first save all your files. R.java is generated once you save xml files. You should have a folder called gen and in it a package and in that package R.java. If you still don't see it try Project -> Clean -> (Then make sure your project is checked and hit ok). If you still don't have R.java then something is wrong with one or more of your xml files so then I would suggest you post your layout xml files so we can help you and see if there are any mistakes in those xml layout files.
Was This Post Helpful? 0
  • +
  • -

#3 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Re: R.id not found

Posted 05 August 2012 - 08:40 PM

Oh, I would like to clarify, I do have the R.java file, but it doesn't have an id section in it. Here's my xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff" >
    
    <ImageButton 
        android:id="@+id/Sound_Button"
        android:layout_width="wrap_content"
        android:layout_height ="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/Sound on"
        android:contentDescription="@string/Image_Desc"/>


</LinearLayout>



Edit: I tried the clean the project, and for some reason the R.java file is now deleted. I had an error referring to it. So could that have caused it to delete?

This post has been edited by superkb10: 05 August 2012 - 08:51 PM

Was This Post Helpful? 0
  • +
  • -

#4 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: R.id not found

Posted 05 August 2012 - 08:47 PM

ok I see what your problem is! You have an image resource called Sound on but resource names cannot start with a capital letter and cannot contain any space. Just right click on the resource and rename it to sound_on and then change it in your xml and you should be fine!
Was This Post Helpful? 1
  • +
  • -

#5 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Re: R.id not found

Posted 06 August 2012 - 07:24 AM

Oh, it worked! Thanks a ton. I have been looking forward to developing for Android in Eclipse for a long time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1