0

I really need help out here. I am a beginner to android programming and i wanted to make a simple sudoku game. But i cant proceed further without this problem being resolved.My R.java file is not being generated.Here is the code -

package org.example.sudoku;



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

public class Sudokugame extends Activity {

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


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

}

it says R cannot be resolved into a variable. And R.java file is missing in the gen folder. P.S - none of my files start with a capital letter in the res folder so thats not the error.

here is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/main_title"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/continue_label"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/new_game_label"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/about_label"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/exit_label"/>
    </LinearLayout>

and here is my strings.xml code :

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Sudoku</string>
    <string name="main_title">Android Sudoku</string>
    <string name="continue_label">Continue</string>
    <string name="new_game_label">New Game</string>
    <string name="about_label">About</string>
    <string name="exit_label">Exit</string>

</resources>

And here is my androidmanifest.xml code :

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

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="org.example.sudoku.Sudokugame"
            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>
  • 1
    u need to clear project. – PankajAndroid Mar 31 '14 at 05:41
  • Once clean the project and then try to execute. – RobinHood Mar 31 '14 at 05:42
  • possible duplicate of [R.java file not getting generated](http://stackoverflow.com/questions/11869307/r-java-file-not-getting-generated) – Hungry Blue Dev Mar 31 '14 at 05:44
  • Delete any import to an R.java class. Move your cursor to a reference to any button/layout/string/whatever-coming-from-R, delete the last character, and hit ctrl+space. Eclipse will try to codehint you, automatically importing the correct R.java. Just to keep it cool, clean and rebuild. – IntelliJ Amiya Mar 31 '14 at 05:45
  • 1
    This is because you will have errors in Manifest file or XML files. Please make sure you don't have any errors in the following. Once done,clean and import – Mohammed Imran N Mar 31 '14 at 05:47
  • Clean your project and build it again. Check if the same problem persists.. – TheLostMind Mar 31 '14 at 05:48
  • Check your XML files. Like Uppercases in XML files,id,drawable...something will be the issue – Kalai.G Mar 31 '14 at 05:48
  • @ambigram_maker - how do i make sure i have R.java file? i cant modify it because it has to be automatically generated. – user3147192 Mar 31 '14 at 05:59
  • there was no errors in the manifest or xml file..what sort of errors are you talking about?@MohammedImranN – user3147192 Mar 31 '14 at 06:00
  • once restart eclipse and then clean and build your project. – Kanwaljit Singh Mar 31 '14 at 06:48
  • Not an answer, just a consideration: Are you sure you want to support devices **from API Level 1** (no more existing device uses it) and target only **Froyo**? – Phantômaxx Mar 31 '14 at 06:48
  • yeah ..thats because i have installed only froyo. – user3147192 Mar 31 '14 at 06:49
  • minSdkVersion should be **8** (previous version of the OS are **dead**, the first 2 are **unsupported**), according to the worldwide statistic of active devices. **Froyo** is only the **1.2%** of the market (as of 2014-03-04). – Phantômaxx Mar 31 '14 at 06:52

3 Answers3

0

R.java not being generated is most often due to a problem with one of the resource or manifest XML files. Review the Problems or Console windows to check/

The other issue that arises is the ADT plugin sometimes inserts extraneous "import R.java..." statements, especially after any renaming or other manipulations of package names. There usually shouldn't be any of those types of imports and they can be deleted.

After resolving any errors, and perhaps even as an extra first step, you'll want to clean and rebuild your project.z

Sometimes the error is as simple as using an invalid character in one of the resource file's name. Only the characters a-z, 0-9, underscore and period are valid. Uppercase letters and dashes are not allowed.

EDIT:

Another possibility is an outdated ADT. The ADT can get outdated whenever the SDK gets updated. Here's how to update the ADT:

In Eclipse, go to Help > Check for Updates. Then look for items with Android or ADT in the name. Select all of them and follow the wizard.

If you get "No updates were found." or don't see any relevant items in the list, then you'll have to do an install rather than an update. This page describes the installation process, but the short version is to do the following. Go to Help > Install New Software..., then click on the Add... button.

Choose and enter a name (such as "ADT") in the name field and enter "https://dl-ssl.google.com/android/eclipse/" for Location. Click on OK and select at least "Developer Tools" in the resulting list. Then click on Finish and follow the wizard.

You'll have to accept a licenses agreement and say OK for a for a validation warning.

scottt
  • 8,301
  • 1
  • 31
  • 41
  • hey, i tried checking for errors in the androidmanifest.xml but as far as i know, it was fine. What might be the error? thanks – user3147192 Mar 31 '14 at 06:02
  • Are you sure none of your layout, string, or other resource files have any issues? You can also open the "Error Log" view to double check, but be prepared to see a bunch of various Eclipse plugin errors that are unrelated to Android (and apparently not real problems.) – scottt Mar 31 '14 at 06:16
  • yeah im pretty sure none of them have any issues. – user3147192 Mar 31 '14 at 06:20
  • Are all of the strings mentioned in your layout file defined OK? – scottt Mar 31 '14 at 06:28
  • yeah i just edited my question so that you can have a look at my xml files . Please do have a look – user3147192 Mar 31 '14 at 06:29
  • I just created a new project, copied in your file content, and after commenting out your onCreateOptionsMenu() method, was able to successfully build the project. I now suspecting it's something wrong with your eclipse configuration. Have you perhaps recently updated the SDK, but not the ADT? – scottt Mar 31 '14 at 06:39
  • that might be the problem. What should i do? – user3147192 Mar 31 '14 at 06:42
  • In Eclipse, go to Help > Check for Updates. Then look for items with Android or ADT in the name. Select all of them and follow the wizard. – scottt Mar 31 '14 at 06:57
  • okay i just updated it. my sdk version was 22.3..it said min sdk version required is 22.6.2 . So im updating that too..it might take a while . if i have further problems , i'l know whom to ask now :) – user3147192 Mar 31 '14 at 07:06
  • I'll update my answer with these steps to make them easier to find. – scottt Mar 31 '14 at 07:08
  • It doesn't do much (yet), but yes it ran fine on my device. – scottt Mar 31 '14 at 07:17
  • okay..il get back to you after it gets updated..thanks a ton for the help – user3147192 Mar 31 '14 at 07:21
  • Hey. I updated my adt as per your instructions . Yet my R.java file doesnt get generated. – user3147192 Mar 31 '14 at 12:59
0

enter image description here

Clean and followed by Build Project it will surely generated R.java file in gen foloder. if in case you have Some error in layout file (.xml) it will not generate so please make sure that check your whole project and rectify your error in both .xml and java file.

Thank you.

Sethu
  • 430
  • 2
  • 13
-2

Try to Change your Manifest file.

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

to

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

Once you create one activity for minsdkversion="1" it will work. But if you try to create another activity for that Project you will get the error. So make sure that you have to set at least minSdkVersion="7" then it will work.

andrewsi
  • 10,807
  • 132
  • 35
  • 51
Sethu
  • 430
  • 2
  • 13