Search code examples
androidr.java-file

R cannot be resolved


package com.ustr.eMIRnew;

import java.util.ArrayList;
import java.util.HashMap;
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

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

This is my code. But it is showing the error R cannot be resolved.
I have tried many methods like clean-and-build, closed-and-open the project, changed import android.R to import your.package.name.R etc. But nothing helped. Can anybody help me, please?


Solution

  • You are Importing android.R package, which is default one provided by Android. If you want to access your own Layout, assets, String. . . then Remove the import android.R statement.

    No need to import your Package.R, By default, R file is generated during built.