Furqan Khyraj
Furqan Khyraj

Reputation: 17

setContentView(R.layout.main); main is showing error

Here is coding

package todo.list;

import android.R;
import android.R.layout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class TodolistActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btnSave = (Button)this.findViewById(R.id.button1);
        final EditText txtEdit=(EditText)this.findViewById(R.id.edit);
        btnSave.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
            // TODO Auto-generated method stub
            String message = txtEdit.getText().toString();
            Toast.makeText(TodolistActivity.this, message, 20).show();
             }
        });

    }

}

I import all classes but still its showing an error with connection to my main.xml

setContentView(R.layout.main); 

main is showing error

MAIN CAN NOT BE RESOLVED OR IS NOT A FIELD

Upvotes: 1

Views: 11434

Answers (5)

javier
javier

Reputation: 1

In my case,I resolve the error by moving the java file to /src/my_project where my_project is the name package where the main activity is taking place

Upvotes: -2

Guest1
Guest1

Reputation: 1

In my case,I resolve the error by replacing,

setContentView(R.layout.main); with

setContentView(R.layout.activity_starting_point);

which was the name of the activity I specified while starting the project.

Upvotes: 0

AbuQauod
AbuQauod

Reputation: 919

clean your project then re build it again

projects -- > clean

projects --> build all

Upvotes: 2

Paul Burke
Paul Burke

Reputation: 25584

Delete these lines:

import android.R;
import android.R.layout;

If using Eclipse, hit Command(Cntrl)+Shift+O after, or replace with

import todo.list.R

Upvotes: 2

Sergey Kuryanov
Sergey Kuryanov

Reputation: 6114

Replace

import android.R;
import android.R.layout;

to

import todo.list.R

Upvotes: 0

Related Questions