• 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
Jul 29, 2011
9
0
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
 
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
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones