Arihant
Arihant

Reputation: 4047

R cannot be resolved into a variable - Android- Eclipse Fresh Project

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

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

Upvotes: 1

Views: 1686

Answers (5)

abhi
abhi

Reputation: 759

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.

Upvotes: 1

Patrik Onderka
Patrik Onderka

Reputation: 106

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 ;-).

Upvotes: 1

Arihant
Arihant

Reputation: 4047

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

Worked fine for me

Upvotes: 0

Nizam
Nizam

Reputation: 5731

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.

Upvotes: 0

amalBit
amalBit

Reputation: 12191

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.

Upvotes: 0

Related Questions