Reputation: 75
So like others I have this little bit of code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
The problem is that main cannot be resolved or is not a field
. main
in the code is underlined in red.
What I have tried due to other answers:
I have cleaned the project and rebuilt it every time I tired each suggestion and error has still not gone away.
I am using Eclipse, Juno, as well as Android and Google plugins.
Any suggestions?
Edit: Ok. In the folder res>layout> activity_main.xml is the correct name.
I have tried to type
setContentView(R.layout.activitymain);
and setContentView(R.layout.activity_main);
but the error is still there.
When I type
R.layout.
and then wait for the suggestions the first thing on the list is activity_list_item : int - R.layout
(There is no other suggestions in the list that include the word main or activity?)
Cannot attach list due to only being new on here and not enough reputation
Upvotes: 0
Views: 945
Reputation: 44571
This
setContentView(R.layout.main);
needs to be
setContentView(R.layout.activitymain);
Since that is the name of your xml file that is what you inflate in setContentView()
. It is currently looking in "res/layout" for a file named main.xml
when it should be looking for activitymain.xml
or whatever the name of the xml file is that you want to use for your layout
Upvotes: 1
Reputation: 486
change
setContentView(R.layout.main);
to
setContentView(R.layout.activitymain);
Unless you have a layout called main.xml in your layout folder
Upvotes: 0