Johnny Rottenweed
Johnny Rottenweed

Reputation: 337

SetContentView cannot find resource

I am new to Android environment. For some reason, I am getting errors when trying to build. Specifically, these types where by the activity_main.xml layout file is being reported as not being found. However, I do see it there. There seems like there might be something messed up in my environment but I don't know what? I consistently get these types of error whether the resource exists or not.

setContentView(R.layout.activity_main);

Any help appreciated.

Upvotes: 1

Views: 5706

Answers (5)

Felix Savali
Felix Savali

Reputation: 1

Check for typos in your package names. If you have renamed any of your package folders, 90% of the time this error is caused by typos in the AndroidManifest.xml file. Check if your matches your package names on app/java/com/packagename/yourappname

Upvotes: 0

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33534

Try these.........

- 1st when you create a ,XML file like main.xml file, you will need a Class that extends Activity and that must be mentioned in AndroidManifest.xml file.

- Clean the Project.

- Close Eclipse, and start it again. Don't Restart but Close it. Eclipse does behave weirdly.

Upvotes: 1

dymmeh
dymmeh

Reputation: 22306

I'm assuming you are importing the wrong "R" file..

Check your imports in your activity.. see if you have import android.R;

If so, delete it.. and make sure you import the proper R file for your own project

Upvotes: 3

Dzhuneyt
Dzhuneyt

Reputation: 8701

Check if activity_main.xml exists in the res/layout folder (make sure it's not inside res/xml instead). If it exists in the correcti directory, try opening it and check if there are any errors.

Also, rebuild your project by running Project -> Clean to make sure all resources are reloaded.

Upvotes: 0

Ted Hopp
Ted Hopp

Reputation: 234807

If you have an error in one of your XML files, the resource compiler may not have generated an R.java file. This would then cause errors when you reference any resource ID in code.

Always fix any problems in the XML files before worrying about resource IDs not being found in code.

Upvotes: 0

Related Questions