1

Firstly, I have to say that I am just a beginner with the Android programming, and I may not understood things correctly. ^^

Secondly, my problem is that the R file (the one which create the different IDs of the objects) just stopped to create new ones.

I noticed that when I created a new image_button at the main_layout and when I tried to look for it on the MainActivity it wrote that it didn't exist.

Moreover, only after I modify the R file (which I should not touch according to the system warning), I have control over the new IDs.

And after breaking my head for two days - I decided to ask you,

The R file:

public final class R {
    public static final class attr {
}

public static final class dimen {
    /*  Default screen margins, per the Android Design guidelines.

     Customize dimensions originally defined in res/values/dimens.xml (such as
     screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.

    */
    public static final int activity_horizontal_margin = 0x7F040000;
    public static final int activity_vertical_margin = 0x7F040001;
}

public static final class drawable {
    public static final int ic_launcher = 0x7F020000;
    public static final int loading_i = 0x7F020001;
}

public static final class id {
    public static final int action_settings = 0x7F080004;
    public static final int button1 = 0x7F080001;
    public static final int imbt = 0x7F080003;
    public static final int textView1 = 0x7F080000;
    public static final int tv1 = 0x7F080002;
}
public static final class layout {
    public static final int activity_main = 0x7F030000;
    public static final int firstpage = 0x7F030001;
    public static final int loading_screen = 0x7F030002;
}
public static final class menu {
    public static final int main = 0x7F070000;
}
public static final class string {
    public static final int action_settings = 0x7F050001;
    public static final int app_name = 0x7F050000;
    public static final int hello_world = 0x7F050002;
}

The creation of the new object:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageButton
    android:id="@+id/imgBtn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"    />

</LinearLayout>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
YanivGK
  • 893
  • 12
  • 18
  • Try to clean and rebuild project. You shouldn't touch R file with your hands. It should be automatically generated by your IDE. – Anatol Jan 04 '14 at 19:56
  • Possible that there's an error in your resources that prevents the resource compiled from finishing and an old version of `R.java` remains in place. – laalto Jan 04 '14 at 20:08
  • The [r] tag is for the language by that name. – IRTFM Jan 04 '14 at 20:23
  • I found the problem, thanks everyone I am really appraise it :) – YanivGK Jan 04 '14 at 21:20

4 Answers4

1

Yep, you shouldn't edit the R file directly. The problem you meet is normal. It should be causes by a file out of sync.

Hopefully, you could fix it by:

Option #1: Try to refresh whole project and 'Project -> build project'.

Option #2: If #1 doesn't work, hit 'Project - clean...', and then rebuild the project.

Option #3: Sometimes, #1 and #2 don't work. The last ultimate way,
which always works for me, is to delete the `gen` folder and rebuild the project.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
windkiosk
  • 490
  • 2
  • 10
1

It's one of the most common problems beginners face; even I faced this too. :)

The most obvious solution is to try cleaning and building your project. Sometimes it works, and most of the times it doesn't.

When cleaning and building doesn't work, then most likely you have some error in your code and that too in XML files. Android tools sometimes don't show which XML file has the error, so you manually need to open each file and check for errors. Once you have fixed the errors, your R.java will build automatically.

I hope this helps.. :)

Update:

This used to happen for Eclipse and ADT plugin. Android Studio is the savior. Start using it if you aren't already.

Ankit Popli
  • 2,809
  • 3
  • 37
  • 61
1

Make sure that

Project --> Build Automatically

If it's already checkedm, run clean:

Project --> clean

If that doesn't work, then most likely there is an error in one of the files, most likely one of the layout XML files. Check the Problems view:

Window --> Show View --> Problems.

Fix all the problems (you can ignore the warnings).

Your last resort is to delete the R file (backup first) and then re-built (or clean).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Or Bar
  • 1,566
  • 11
  • 12
0

Clean your project and run it:

Project---> Clean then run

See Stack Overflow question Developing for Android in Eclipse: R.java not generating. It gives the perfect solution for you...

Change the build target version and clean the project. After completing that, change that build version to previous. It works for me.

Community
  • 1
  • 1
balaji koduri
  • 1,321
  • 9
  • 25