R cannot be resolved

不想你离开。 提交于 2020-01-15 03:11:06

问题


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?


回答1:


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.




回答2:


You are using the android R file you have to use you package R file if you want to access the main layout for you app. import you_package.R




回答3:


Remove the import statement:

import android.R;

In the onCreate method where you set the content view to R.layout.main, your project should be using this file:

com.ustr.eMIRnew.R

This file is generated when you build your project. Are you using Eclipse for building? Then this should not be a problem.



来源:https://stackoverflow.com/questions/5298231/r-cannot-be-resolved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!