Error: setContentView(R.layout.main) in Android Studio
I found the answer by my self. I thing the error is not because of wrong import as answered here. It was because of the use of wrong name
and id
of layout file and check box
respectively. My .xml
layout file name was activity_my_checkbox.xml
. So I should use:
setContentView(R.layout.activity_my_checkbox);
And my check box id was c
instead of check
, so I should use
cb=(CheckBox)findViewById(R.id.c);
setContentView(R.layout.main); Gives error from start
this is quite a common mistake .
make sure that at the top of your java file of the activity , the import is not of android.R.layout (or whatever) ,since it should import the R of your own app (which is inside the gen folder).
if you still have problems with that , try to delete the gen folder , make sure the layout file is ok (meaning it's a correct android layout file, without any mistakes), make sure all of the resources (all images, sounds , xml files , all that are in /res) have only the legal characters in their files names (which means they are lowercase english ,optionally with "_" and digits, but no more) , clean the project , and then import the generated file .
you can also use CTRL+1 on the red underline of the R that it complains about , and choose the one of your project.
setContentView(R.layout.main); error
Just take 2 steps and problem would be more likely to get solved:
Step 1:
Clean your project by clicking Project -> Clean.
Step 2:
Rebuild your project by clicking Project -> Build All.
Also make sure that your layout xml files are syntax error free and you don't have any image which has non-acceptable names (such as a "-" between image name).
Also I request you to have a look at problems window and let me know what errors are being shown there.
Android Studio: setContentView(R.layout.activity_main); error:cannot resolve R
I dont know what the problem was, I tried a few of the solutions provided here: Execution failed app:processDebugResources Android Studio
None of them worked though. i just reinstalled Android Studio and did not update any of the build tools and its working fine now.
Android - setContentView(R.layout.main);
Change
setContentView(R.layout.main);
to
setContentView(R.layout.activity_main);
as you dont have an xml file named main.xml in your layout folder..
Related Topics
How to Make Push Notification With Specific Sound
Control the Playback Speed of Video in Android
How to Fix Mainactivity Does Not Have a Navcontroller
How to Make a Link Open an Instagram Page in an App Installed on Android
How to Connect Existing Android Studio Project to Existing Github Repository
How to Get Root Access on Android Emulator
Android Studio - How to Find Valid Certification Path to Requested Target
Android Studio - Failed to Apply Plugin [Id 'Com.Android.Application']
How to Set Transparency of a Background Image Android Xml File
How to Set the Height of an Item Row in Gridlayoutmanager
How to Remove Focus from Edittext When User Is Done Editing
How to Quit Android Application Programmatically
Getting Simple Json Object Response Using Retrofit Library
Could Not Resolve All Dependencies for Configuration ':Classpath'
Illegalstateexception: Link Does Not Have a Navcontroller Set
How to Set Value for Each Item Button Increase and Decrease Click and Set That Value in Text View