• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps The type R is already defined?

pjl83

Lurker
Hello,

I am writing an example programme as I am learning to programme android apps for the first time. I have followed the instructions to the letter but I have some errors with the R files?

Here is my R.java file:


/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/

package com.dummies.android.silentmodetoggle;

public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
public static final int phone_on=0x7f020001;
public static final int phone_silent=0x7f020002;
}
public static final class id {
public static final int phone_icon=0x7f050000;
public static final int toggleButton=0x7f050001;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}


On the line hi lighted in red I have an error under the R. It says that "The type R is already defined".

I have lots of errors on my main activity coding too but they all relate to the R. Where should I begin in finding the fault? As the R.java file was derived I cannot understand where the fault can be coming from.

Thank you in advance for any help.
Paul
 
I'm quite new to all of this but I've found that I've needed to clean and rebuild the app when I change any resources or references to resources.

Hope this helps...
 
Make sure you don't have Android.R in the import statements in any of your activities.

Then do a clean as ItWorksDev suggested:
Project --> Clean
From the menu I believe.

Also if you are on Win 7 or Vista try running Eclipse as Admin, right click Eclipse, "Run as Administrator"
 
Hi,

Thank you for your ideas.I have tried but cannot resolve. I have done a print screen showing the tree of files expanded and the errors at the bottom.

printcreenerrors.jpg


Any ideas?

Thanks
Paul
 
You never need to edit R class so I would just close that since it doesnt tell us anything. lets see MainActivity . Also are you running as Admin?
 
Hi.

I am now running as Admin yes. I just happened to notice in the tree (as you can just about see above) that I somehow had 2 R.java files so I deleted the rogue one and it clear the majority of the errors.

I have cleaned and rebuilt. The only errors I have now are with the setButtonClickListener lines?

Untitled.jpg


Any advice would be greatfully received.

Thanks in advanced.
 
Thanks for the help tzcoder. I've managed to get the app running now. I used a combination of your hints and the suggested fixes in eclipse. There are a couple of glitches so I'll do a save as and have a play. It's frustrating as I'm following a guide and I did everything word for word. I think I'll go back to the beginning and do more reading so I have a better chance of fault finding.

Thanks again
Paul
 
Back
Top Bottom