1

Just started development for android and now i have an error as soon as i create a new project which says R Cannot be resolved to a variable

  • I tried rebuilding
  • I tried setting paths
  • I checked XML and Manifest
  • The R.java file doesnt exists

here's the java file of the activity

package com.pingcampus.pc;

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

public class Startingpoint extends Activity {

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

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

}

and here's the manifest of the application:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pingcampus.pc"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.pingcampus.pc.Startingpoint"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest> 

Also as someone demanded .. Here's the XML(activity) code as well

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Startingpoint" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

</RelativeLayout>

CONSOLE ERRORS (AFTER RESTARTING ECLIPSE)

    [2013-06-20 19:06:12 - Pingcampus] 'default' is not a best match for any device/locale combination.
[2013-06-20 19:06:12 - Pingcampus] Displaying it with ', , Locale Language ___Region __, , sw320dp, w320dp, h533dp, Normal Screen, Long screen aspect ratio, Portrait Orientation, Normal, Day time, High Density, Finger-based touchscreen, Soft keyboard, No keyboard, Hidden navigation, No navigation, Screen resolution 800x480, API Level 17' which is compatible, but will actually be displayed with another more specific version of the layout.

help!

HERE'S A SCREEN SHOT OF THE WINDOW Screen grab of the window

Arihant
  • 3,847
  • 16
  • 55
  • 86
  • Did you check the Console? – Carnal Jun 20 '13 at 11:13
  • check if you have any error in you resource files. If so fix them. Goto android sdk manager and check that you have the android sdk build tools installed. This many not be necessary but make sure you have android build tools installed. try this if you have updated adt to rev 22 – Raghunandan Jun 20 '13 at 11:14
  • Console? What's that? I am new to this environment, sorry i sound a newbie @Carnal – Arihant Jun 20 '13 at 11:14
  • Window > Show View > Console. Usually it says there what the problem is! – Carnal Jun 20 '13 at 11:15
  • Can you tell me what is in your xml file .. – Amsheer Jun 20 '13 at 11:57
  • @Carnal the console is empty – Arihant Jun 20 '13 at 13:01
  • http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error?rq=1 view the solution for this question. –  Jun 20 '13 at 13:09
  • I am pretty sure i have all the things updated – Arihant Jun 20 '13 at 13:16
  • check the Problems tab and share with us what is the problem , i think to problem is about your xml resources ( layout names , drawable names ..etc ) – Houcine Jun 20 '13 at 13:45
  • This works: http://stackoverflow.com/questions/16608524/eclipse-giving-error-missing-r-java-file-after-recent-update?lq=1 –  Oct 02 '13 at 22:21

5 Answers5

1

If you added any image in drawable folder then please check that your image name is lower case and non-numeric. Then fix project properties by right clicking on the project and selecting Clean Project.

Another problem may be you have not selected the Android library version from project right-click->properties->Android.

Jon Adams
  • 24,464
  • 18
  • 82
  • 120
abhi
  • 759
  • 6
  • 15
  • there are no resources added.. i just created a single fresh project with a blank activity along with it i am attaching an image with the questin so that you all can have a better look – Arihant Jun 20 '13 at 12:59
1

I met a similar problem while ago. All the typical solutions as described in other answers didn't help. Eventually, the problem was caused by unistalled SDK build tools from the Android SDK Manager. Not even sure how it happened. But after installing it back, it start working. Not sure whether it might be your case, but it took me a while to solve it out ;-).

0

The eclipse builds your project the moment you load it: Only then it will create the contents in the gen and bin.

Now if there is any resource related issue like:

-Missing image or xml resource.

-missing library.

Then your bulid process wont be complete. Now if you check your gen folder, there wont be any R.java file. So it will show error throught your project.

Check your project and find out the missing portion.

amalBit
  • 12,041
  • 6
  • 77
  • 94
  • I did check, as a begineer, i am not very sure whether everything is okay or not, could you please give it a look? – Arihant Jun 20 '13 at 13:23
  • Check for errors in your layout file.. and post it in question, if you are using library, check whether its in the dependancy folder. – amalBit Jun 20 '13 at 13:27
0

You did nothing, but just created a new project and its R.java is missing. Isn't it?

If you didn't touch resources, Try following.

  • Make sure, Project-> Build automatically, is checked.
  • Project-> clean
  • If problem continues, file-> Restart and then project->clean

If problem persists, there is problem with your Java compiler.

Nizam
  • 5,698
  • 9
  • 45
  • 57
  • Yep that's what i did, but now suddenly the console gives 2 errors on restarting eclipse. Editing the question to display the console errors – Arihant Jun 20 '13 at 14:26
  • Creating another new project carries the same problem? – Nizam Jun 20 '13 at 14:38
0

Uninstalled Everything and Downloaded the ADT available on http://developer.android.com/sdk/index.html

Worked fine for me

Arihant
  • 3,847
  • 16
  • 55
  • 86