MPKenning
MPKenning

Reputation: 569

Error in R.java

There is an error in R.java in this code on the second line

 public static final class id {
    public static final int 2ndQ=0x7f05000a;
    public static final int FirstQuestion=0x7f050000;
    public static final int MainTitle=0x7f050003;
    public static final int SecondQuestion=0x7f050008;
    public static final int btnstrt=0x7f050007;
    public static final int editText1=0x7f050001;
    public static final int imageView1=0x7f050006;
    public static final int maindescrip=0x7f050004;
    public static final int radio0=0x7f05000b;
    public static final int radio1=0x7f05000c;
    public static final int radio2=0x7f05000d;
    public static final int radioGroup1=0x7f050009;
    public static final int toq1=0x7f050005;
    public static final int toq2=0x7f050002;
    public static final int toq3=0x7f05000e;

It gives me this error

Syntax error on token "2", delete this token

I try to delete that line as it is the ID for a TextView I no longer have. Infact, I changed the ID of the TextView to "SecondQuestion" from "2ndQ".

How do I get rid of the error? It's preventing me from testing my app.

EDIT: Just to clarify this, the id is not present in my project AT ALL.

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

    <TextView
        android:id="@+id/SecondQuestion"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="@string/secondQ"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:textSize="25dp"
        android:textStyle="bold" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/2ndQ"
        android:layout_below="@+id/2ndQ"
        android:layout_marginTop="74dp" >

        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/q2Answer1" />

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/q2Answer2" />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/q2Answer3" 
            android:gravity="center" />
    </RadioGroup>

    <Button
        android:id="@+id/toq3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="@string/buttonForQuestion3"
        android:textSize="20dp"
        android:clickable="false" />

</RelativeLayout>

Upvotes: 2

Views: 6701

Answers (6)

deepGrave
deepGrave

Reputation: 410

After 5 hours, I finally Got to the bottom of this hell! I had this error too, but none of the above mentioned methods helped, apparently i have renamed by mistake an id in a file that belongs to android internal, and not only that - i renamed to sth illegal (@+id/@+id/checkbox_spinner) Using notepad++ search i located the file in c:\Users\.android\build-cache... I erased the build-cache folder, the next start of AS was naturally slower as it created all the necessary files, and WOALLA! problem fixed!

Upvotes: 2

Niallty
Niallty

Reputation: 124

I had this exact problem too. Where there was an error in my R.id saying to delete the token, but I was unable to remove it as it was no longer defined anywhere in my xml. So I had a

public static final int 2ndQ=0x7f05000a;

in my R.java that I couldn't get rid even if I cleaned my project.

To get rid of it I had to

  • Recreate a TextView with this bad id of '2ndQ'
  • Clean the project and update R.java
  • Then delete the sacrificial TextView I had just created

Voilà, Your R.java should be fixed.

Upvotes: 0

XLC
XLC

Reputation: 1

Make sure the elements in your xml files are not empty. The R file doesn't like it when there's an un-use or empty element with no values. For example:

Line 1: Average Height

Line 2:

The R file doesn't like it when line 2 has empty values.

Upvotes: 0

dubman23
dubman23

Reputation: 29

I had a very similar error message starting off with Android development. In my case it was a simple naming error on one of the res strings - I had android:id="@+id/edit/message". The second / should have been an underscore.

The only error message was in R.java so when starting out with development was very confusing.

Upvotes: 3

Graham Smith
Graham Smith

Reputation: 25757

I try to delete that line as it is the ID for a TextView I no longer have

Sounds like the R.java file has not updated, try some of these general pointers to begin with:

  • Do not manually edit any of the files in the gen folder, as these are automatically built for you.
  • If you find it is out of sync then try refreshing the project.
  • If that did not work try a clean (project -> clean)
  • If that did not work delete the gen folder, from within Eclipse, (do not panic) it will then be rebuilt by Eclipse - however if there is a coding error of some sort it may not do this straight away.

Upvotes: 7

AkashG
AkashG

Reputation: 7888

Clean and build your application and try to run your application again..Don't do anything in R.java its automatically generated.Goto Project and clean it,build it.And try to run again.

Upvotes: 1

Related Questions