0
votes

There are plenty of references on stack overflow about R not resolving. I seem to have tried everything recommended. I've clicked Android 4.4 in the build path. There is no "import Android.R" for me to remove. The layout xml file does not currently have any errors. I've imported package.name.R (with my actual package name). I have checked for updates and found none. This is a fresh install of Eclipse and the Android SDK\ADT plugin as of today. Still, nothing works. I can't get a R file in my gen folder.

Let me tell you what I did and see if there is some strange setting I missed. I'm doing this on Eclipse Keplar on the Mac.

File->New->Project

Select Android Application Project and hit Next.

Set Application Name to stacktest and hit Next.

Not checked:

Create custom launcher icon

Mark this project as a library

Add project to working sets

Checked:

Create activity

Create Project in Workspace

Select Next.

Create activity is checked and Blank Activity is selected. Select Next. Then select Finish.

I now have two errors relating to "R cannot be resolved to a variable" in MainActivity.java, for R.layout.activity_main and R.menu.main

Cleaning the project does nothing here. When I try to generate a javadoc I get this long list of problems:

oading source files for package com.example.stacktest... Constructing Javadoc information... /Users/mmarino3/Documents/workspace/stacktest/src/com/example/stacktest/MainActivity.java:3: package android.os does not exist import android.os.Bundle; ^ /Users/mmarino3/Documents/workspace/stacktest/src/com/example/stacktest/MainActivity.java:4: package android.app does not exist import android.app.Activity; ^ /Users/mmarino3/Documents/workspace/stacktest/src/com/example/stacktest/MainActivity.java:5: package android.view does not exist import android.view.Menu; ^ /Users/mmarino3/Documents/workspace/stacktest/src/com/example/stacktest/MainActivity.java:7: cannot find symbol symbol: class Activity public class MainActivity extends Activity { ^ /Users/mmarino3/Documents/workspace/stacktest/src/com/example/stacktest/MainActivity.java:10: cannot find symbol symbol : class Bundle location: class com.example.stacktest.MainActivity protected void onCreate(Bundle savedInstanceState) { ^ /Users/mmarino3/Documents/workspace/stacktest/src/com/example/stacktest/MainActivity.java:16: cannot find symbol symbol : class Menu location: class com.example.stacktest.MainActivity public boolean onCreateOptionsMenu(Menu menu) {

I am having the same problem in any and all android projects I create. Anyone know what the problem could be?

3

3 Answers

0
votes

Create custom launcher icon Mark this project as a library Add project to working sets

Is there a non-library project as a part of your solution?

  1. I would have thought you have a project with a custom launcher - done.
  2. Add another project as a library project - done.
  3. Add reference to library project to original project.

I found it strange that you are creating a launcher and also marking it as a library.

0
votes

Ok. it has made your main activity in com.example, but you said you had a different package name.

Go into your AndroidManifest.xml and confirm what the package name is under the package attribute of the application tag. This is where your R file has been generated.

Remove the manual import link to an R file you have created inside the MainActivity.

Try CTRL + SHIFT + O and see what it asks you for.

Basically I don't think your java package is matching your AndroidManifest declared package.

0
votes

I have the same problem.

I just go through the following steps:

  1. Clean Project (Android Studio -> Build -> Clean Project)
  2. Rebuild Project (Android Studio -> Build -> Rebuild Project)

The second answer is: Just disable the power save mode in Android Studio (in Android Studio -> bottom end right side -> click on man with cap -> and just uninject the power save mode)