2

I have the famous error message “R cannot be resolved to a variable” since the last 3 days and I’m totally stuck. I did follow the instructions in the following links but I can’t remove this error: Developing for Android in Eclipse: R.java not regenerating

I have crated plenty of new projects with just a new title but the same.

I even today uninstall completely Eclipse , jdk, jre and reinstall all but the same…

**Config: Windows 7 64 bits

eclipse-standard-kepler-SR1-win32-x86_64

jdk-7u51-windows-x64

jre-7u51-windows-x64

Android sdk downloaded**

I have noticed there is no file in the folder “gen” is always empty..

Thank you for your help ![enter image description here][1] ![enter image description here][2] ![enter image description here][3] ![enter image description here][4]

Mainactivity.java:

package com.example.test1;

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

}


activity_maim xml

 <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=".MainActivity" >

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

</RelativeLayout>

manifest.xml

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.test1.MainActivity"
        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>
Community
  • 1
  • 1
user1805
  • 187
  • 2
  • 6
  • 15
  • clean the application i.e go to project -> clean then select your project and clean it.. – Ranjit Feb 09 '14 at 16:27
  • This usually happens when you have made a mistake in your xml files. Can you try adding the code of your MainActivity? – Nitin Sethi Feb 09 '14 at 16:29
  • already done plenty of times and it doesnt change anything – user1805 Feb 09 '14 at 16:30
  • ?Also can you please copy your code instead of screenshots? – Nitin Sethi Feb 09 '14 at 16:32
  • How can I made a mistake with xml file when I only click on "create new android project" with just the title added?Mainactivity file screenshot is added.Thank you – user1805 Feb 09 '14 at 16:33
  • can you post ur mainactivity code – Ahmed Ekri Feb 09 '14 at 16:34
  • Have you tried adding JDK 6? We can't look at the screenshots and type the stuffs to check out if it reproduces in our machine !! :) These screenshots aren't of much help. – Nitin Sethi Feb 09 '14 at 16:35
  • jdk-7u51-windows-x64 has been installed – user1805 Feb 09 '14 at 16:38
  • Try doing the same process using Android Studio, then compare the source. (Unless you have some peculiar fetish for tedium you'd be well rid of Eclipse. Everything seems a lot less painful). –  Feb 09 '14 at 20:32

2 Answers2

1

This looks like a 64bit issue, as android is looking for a 32bit ADT, there are a few options to solve this. Have a look at this question: Android SDK Setup under Windows 7 Pro 64 bit

I solved this under linux by doing sudo apt-get install ia32-libs

Community
  • 1
  • 1
BadSkillz
  • 1,993
  • 19
  • 37
  • Thank you for the link but it looks like it's more related for issue during installation.I could install the jre and sdk without problems. – user1805 Feb 09 '14 at 17:24
  • I know, I had this problem on ubuntu, tried all the regular fixes and nothing worked until I found this: http://stackoverflow.com/a/11963196/480536. So there could still be a 32bit issue. Maybe try 32bit java? – BadSkillz Feb 09 '14 at 20:39
  • actually, that was the only solution but I prefered initially to avoid unistall all and reinstall in 32 bits but it works now with 32 bits.Thank you – user1805 Feb 09 '14 at 23:37
0

Have you checked your manifest.xml for mistakes? I once had a small error in my manifest that didn't show up as an error and it wouldn't generate a new R file.

I noticed another small thing that might be the issue, in your main_activity.xml you use dimension strings for padding, when creating a new project these strings are located in res/values/dimens.xml but in your layout file you are referring to @dimen instead of @dimens (notice the missing 's'). Try changing it to "@dimens/..."

Kalder
  • 1
  • 1