-2

i am new to android app development,

i have just created simple android project, but when it created it shows error.

"R cannot be resolved to a variable" when i press control shift +o

android.R is automatically added to my code but now it shows this error

"activity_main cannot be resolved or is not a field"

this is code of this project

package com.php.helloworld;

import android.R;
import android.app.Activity;
import android.os.Bundle;
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;
    }

}

and when i tried to write this line

import com.php.helloworld.R it shows "The import com.php.helloworld.R cannot be resolved"

There is also no problem in my xml file and and there is no file in gen folder can somebody help me please to resolve this

Arsalan Sheikh
  • 607
  • 7
  • 10

1 Answers1

3

Delete the import android.R. It actually refers to android resource within the android default library. If you want to use your resources you must import your R file not android's default library. Check if R.java is present in gen folder in the project.

Naresh
  • 3,174
  • 1
  • 17
  • 22
  • There is no file in gen folder and my xml is fine because i didn't changed anything there is nothing written by me i just created this is samle hello world only – Arsalan Sheikh Oct 21 '13 at 18:16
  • 1
    its has been solved, i have added android build tools on it and then clean project the errors have been going, thank you naresh – Arsalan Sheikh Oct 21 '13 at 18:36