0

This is the first time I'm using eclipse. Without making any changes in any of the xml files when I run the package, I'm getting errors as: R cannot be resolved to a variable. Following is my source java file:

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

public class StartingPoint extends Activity {

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

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

It gives error on both the lines where R.layout and R.menu is used. Also following is my layout's xml file:

<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>

And menu xml file:

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>

I've tried cleaning and restarting but nothing works and there is no error in the xml files. Kindly let me know how to fix this error. Thank You.

Kanwaljit Singh
  • 4,339
  • 2
  • 18
  • 21
pnk6
  • 276
  • 3
  • 15
  • 1
    And you did the import for R? – Marko Lazić May 19 '13 at 22:42
  • Perhaps try creating a new project and add all files, just as a test? – Dory Zidon May 19 '13 at 22:46
  • No, I haven't imported R. – pnk6 May 19 '13 at 22:48
  • If you've recently updated, try [this](http://stackoverflow.com/questions/16608524/eclipse-giving-error-missing-r-java-file-after-recent-update/16608570#16608570) or [this](http://stackoverflow.com/questions/16610190/classnotfoundexception-after-adt-update/16610247#16610247). It's one of the most common problems in the latest SDK. – Krauxe May 19 '13 at 23:41
  • If you are using Eclipse, check the Eclipse console for other messages, such as errors in your manifest. – CommonsWare May 20 '13 at 00:39
  • Also in Android Virtual Device Manager... Will the following work?? Target--Google APIs(API Level 11) or Android 3.0(API level 1) Device--Nexus One CPU/ABI--ARM(armeabi).. Does this need any change? Esp in target option?? – pnk6 May 20 '13 at 16:26
  • Problem resolved. Only changed the Android version to 4.0.3. – pnk6 May 20 '13 at 16:56

0 Answers0