Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"R cannot be resolved to a variable" just after creating android project? [duplicate]

Just after creating the new Android Application Project I get the error "R cannot be resolved to a variable" in my MainActivity.java file.

This is it's content:

package com.example.firstapp;

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.activity_main, menu);
        return true;
    }

}

Why am I getting this problem if the app was created by Eclipse choosing all the default options? How can I fix this issue?

like image 900
lisovaccaro Avatar asked Jan 04 '13 04:01

lisovaccaro


1 Answers

It might be because, there might be some problem in your res folder,

  • The Main reason might be there could be wrong import file of R.java. So Remove, if any import android.R;

  • There might be some images with same name, or some files with capital letters, or even there might be some errors in your xml files,

  • Try rebuilding and cleaning your project.

For some quick solutions to this problem, have a look at this,

R.java file not getting created

like image 163
Sahil Mahajan Mj Avatar answered Oct 06 '22 12:10

Sahil Mahajan Mj