Parth
Parth

Reputation: 1266

Main layout not recognized, immediately after starting new Android project

The below code was automatically generated when I started a new android project.

I'm getting an error on the "R.layout.main" saying it does not exist.

I do in fact have a main.xml and I can see the layout change as I edit it in the Graphical Layout tab.

How can I fix this so I can run my application?

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

Upvotes: 0

Views: 2044

Answers (3)

onit
onit

Reputation: 6376

The package name of the R file and the package name of your source code may not match. Make sure the package your code is in is the same as the package defined in the manifest file. Otherwise you will need to import the R file with the full package name (ex: com.example.R.layout.main).

If they match, for some reason your R file was not generated properly. Try cleaning your project.

Upvotes: 4

Mrinal Mandal
Mrinal Mandal

Reputation: 235

Try to import the R.java file with the full path inside the main activity class file...

import com.example.packagename.R;

Hope, this will solve your query.

Upvotes: 0

EGHDK
EGHDK

Reputation: 18130

This may be a very simple answer, but it has happened to me before. Try to restart eclipse. File -> Restart

Upvotes: 0

Related Questions