Error under Sudoku.java: "R cannot be resolved to a variable"

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 7948 Views - Last Post: 29 June 2011 - 06:10 PM

#1 Zizeeo  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 106
  • Joined: 06-April 11

Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 28 June 2011 - 07:14 AM

Hey guys I'm making a Sudoku Android app but I'm running into a problem my book doesn't seem to have. The error is "R cannot be resolved to a variable" And here is my code:

package org.example.sudoku;

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

public class Sudoku2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

This post has been edited by Zizeeo: 28 June 2011 - 07:15 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Error under Sudoku.java: "R cannot be resolved to a variable"

#2 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 28 June 2011 - 11:03 AM

R.java is an automatic created/updated file created by the project. It should be located in gen-<my package> R.java(See image below!)
Posted Image
If it is not there you need to have the project generate it for you like so:
At the top of Eclipse click Project -> Clean.
Then select 'clean select projects below' and select your sudoku project.
It should now generate your R.java file!

This post has been edited by H3R3T1C: 28 June 2011 - 11:04 AM

Was This Post Helpful? 1
  • +
  • -

#3 Zizeeo  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 106
  • Joined: 06-April 11

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 04:43 AM

It didn't generate. I tried Project clean multiple times and it still isn't there. Could it be something I have set in Project Properties?
Was This Post Helpful? 0
  • +
  • -

#4 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 09:16 AM

Did you just copy paste the project files from some external source or did you create a new project in Eclipse?
Was This Post Helpful? 0
  • +
  • -

#5 Zizeeo  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 106
  • Joined: 06-April 11

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 09:27 AM

I created a new project.
Was This Post Helpful? 0
  • +
  • -

#6 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 09:45 AM

Hmm... that's weird. When you create a new project in Eclipse it will automaticly create the R.java file. Try making a new project and see if it creates the R.java file like it is supposed to.
Was This Post Helpful? 0
  • +
  • -

#7 Zizeeo  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 106
  • Joined: 06-April 11

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 10:32 AM

OK, got that but now I have an error under mail.xml that says: No resource found that matches the given name (at 'text' with value '@String/main_title'). And my code is:
<LinearLayout 
		xmlns:android="http://schemas.android.com/apk/res/android"
    	android:orientation="vertical"
		android:layout_height="fill_parent"
		android:layout_width="fill_parent">

			<TextView
				android:layout_width="fill_parent"
				android:layout_height="wrap_content"
				android:text="@String/main_title" />
				
			<Button
				android:id="@+id/continue_button"
				android:layout_width="fill_parent"
				android:layout_height="wrap_content"
				android:text="@string/continue_label" />
				
			<Button
				android:id="@+id/new_button"
				android:layout_width="fill_parent"
				android:layout_height="wrap_content"
				android:text="@string/new_game_label" />
				
			<Button	
				android:id="@+id/about_button"
				android:layout_width="fill_parent"
				android:layout_height="wrap_content"
				android:text="@string/new_game_label" />
				
			<Button
				android:id="@+id/exit_button"
				android:layout_width="fill_parent"
				android:layout_height="wrap_content"
				android:text="@string/exit_label" />
		</LinearLayout>

Was This Post Helpful? 0
  • +
  • -

#8 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 10:42 AM

The s in @String/main_title needs to be lower-case. Also make sure that you have the 'main_title' element in your strings.xml which is in Res -> Values -> strings.xml
Was This Post Helpful? 0
  • +
  • -

#9 Zizeeo  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 106
  • Joined: 06-April 11

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 11:33 AM

Alright, I went to run it and it says: [2011-06-29 14:31:16 - Emulator] invalid command-line parameter: jasonsphone. under Console.

This post has been edited by Zizeeo: 29 June 2011 - 11:34 AM

Was This Post Helpful? 0
  • +
  • -

#10 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 11:49 AM

Are you using a phone or an emulated version of android to run the app?
Was This Post Helpful? 0
  • +
  • -

#11 Zizeeo  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 106
  • Joined: 06-April 11

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 12:13 PM

An emulated version.
Was This Post Helpful? 0
  • +
  • -

#12 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 02:38 PM

Ok you may have a bad configuration. Try restarting Eclipse and stopping all emulated android devices. If it still does not work try deleting your virtual devices and creating new ones. Of that does not work right click on your project and select properties. Then select Run/Debug settings and select your project from the list and hit edit. Click on the Target tab and with automatic selected check the avd that you want use for running the app. Hit apply then ok and it should now work if not try having the avd started before you try to run your app.
Was This Post Helpful? 0
  • +
  • -

#13 Zizeeo  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 106
  • Joined: 06-April 11

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 02:51 PM

How do I delete my virtual devices?
Was This Post Helpful? 0
  • +
  • -

#14 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 03:04 PM

You need to open up the Android SDK and AVD Manager by pressing the button in eclipse as seen in the picture below. (circled in red). Select each device from the list and hit the delete button on the right.
Posted Image
http://i.imgur.com/KPPC4.png
Was This Post Helpful? 0
  • +
  • -

#15 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: Error under Sudoku.java: "R cannot be resolved to a variable"

Posted 29 June 2011 - 03:29 PM

You might also need to adjust your run configuration to manual so that you have the option of what device to use.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2