0

Ive just joined StackOverflow because I just cant find any answers to my problem. :(

I have however found other threads on this, and none seem to fix it.. i have no idea why.

So basically, i am trying to make an android app, i start up a NEW project and already the R.Java is missing (causing major issues, and i can't even compile from it :( ), ive tried: import.android.R;, import.(packagename).R;, ive tried to "clean" it, and a bunch of other stuff. Literally everything i can think of.

What is going on, and how can I fix this?

 package com.nicco.compare;

 import android.os.Bundle;
 import android.app.Activity;
 import android.view.Menu;

  public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

  }
Raghunandan
  • 132,755
  • 26
  • 225
  • 256

5 Answers5

2

R.java is auto generated.

 1. Do you have a import statement like import android.R;. If so remove the import

 2. Do you have errors in your xml files. If so fix them

 3. Clean and build project.

My guess your are importing android.R Remove this import statement(import android.R;). Clean and build you project. this should solve your problem.

Right Click on project goto properties choose android on the left. Check you have the right version checked.

Also look for the sdk version in manifest file

enter image description here

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
1

Here's how I fixed this in Eclipse:

Create R.java in gen folder manually and save. After that go to Project and click "Clean" The following message will display and your file will automatically be rewritten:

R.java was modified manually! Reverting to generated version!

This is alternate approach

R is an automatically generated class that holds the constants used to identify your >resources. If you don't have an R.java file (it would be gen/com.techfuze.app_name/R.java in >Eclipse with the 1.5 SDK) I would recommend closing and reopening your project or going to >Project > Build all (and selecting "Build Automatically" while there as recommended by >Josef). If that doesn't work than try making a new project, if the problem is recreated than >post here again and we'll go into more detail.

but I've found out that there was another problem that was causing the first one. The tools in the SDK directory didn't have the permissions to be executed, so it was like the didn't exist for Eclipse, thus it didn't build the R.java file.

So modifying the permission and selecting "Build Automatically" solved the problem.

onkar
  • 4,427
  • 10
  • 52
  • 89
  • ok i tried to make a new manual R.Java, and i hit clean, and once it was done it just disappeared. :/ –  Apr 04 '13 at 12:56
1

try this one ,first "right click" the "project" and than go for the "properties" and select "java build path" and than select "version checkbox" and save changes.

and if it is not working than close your all files and clean the project........

  • hmm i cant see version checkbox, im in the java build path o.O odd. –  Apr 04 '13 at 13:07
0

Try to verify that your layout files (i.e) the xml files don't have any error in them. Because R.java will be generated only when.xml files are clean

Manoj Kumar
  • 1,510
  • 3
  • 20
  • 40
  • the xml's have none, and i havent touched them either, since they were made. –  Apr 04 '13 at 12:50
  • See the console and tel what error its showing – Manoj Kumar Apr 04 '13 at 12:52
  • `[2013-04-04 23:28:49 - Compare] dyld: unknown required load command 0x80000022` (Compare is my project name) –  Apr 04 '13 at 13:02
  • Are you running it in a Mac? especially is the model name is Santa rosa? – Manoj Kumar Apr 04 '13 at 13:25
  • no im just using a MacBook OSX 10.5.8 –  Apr 04 '13 at 13:27
  • see this if it helps http://stackoverflow.com/questions/14462654/this-dyld-unknown-required-load-command-0x80000022-error-is-killing-me-exclamat – Manoj Kumar Apr 04 '13 at 13:28
  • also see the common prob with Mac osx10.5.8 users https://groups.google.com/forum/#!topic/adt-dev/QxradSzgSYk – Manoj Kumar Apr 04 '13 at 13:33
  • everyone on that link and the links within it seem to be using some sort of mac (10.5.8) i guess it must be my computer? but there must be a work around, other than changing or upgrading, surely. –  Apr 04 '13 at 13:36
  • Try importing some other sample programs like hello world and add your coding there and change it into your project :) not much of a workaround but it might do – Manoj Kumar Apr 04 '13 at 13:39
  • ok, ill try that, and if it doesnt work should i downgrade one version of the Android SDK? –  Apr 04 '13 at 13:41
  • I think you better install VM and use windows inside for this as windows and eclipse goes well – Manoj Kumar Apr 04 '13 at 13:42
0

It happened to me when I added a search action but failed to add the search string in values/strings.xml. I then did a clean and the R.java disappeared. Once I added the string, the build succeeded and regenerated the R.java.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
TheMuse
  • 11
  • 5