Android: EditText.getText().toString returns nothing

android, android-edittext, onclick

I want to get value from an edittext view in an onClick method, but there seems to be some problems retrieving the id of the EditText.
here is my code:

public class CreateEvent extends Activity{    Button cbutton;    EditText title;    protected void onCreate(Bundle savedInstancesState){        super.onCreate(savedInstacesState);        setContentView(R.layout.create_event_layout);        cbutton = (Button)this.findViewById(;        title = (EditText)this.findViewById(;        cbutton.setOnClickListener(new Button.OnClickListener()        {            public void onClick(View v){                Log.v("title", title.getText().toString());        });    }}

Also I tried to move initiation of title into onClick, still nothing returned.
Not sure what to do.

this is the layout file:

<LinearLayout xmlns:android=""android:layout_width = "fill_parent"android:layout_width = "fill_parent"android:oriention = "vertical">    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/title"    />    <EditText        android:id="@+id/title"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:textSize="20sp"        android:hint="@string/title"    /></LinearLayout>

I am pretty sure there is nothing wrong with my layout file.

Best Solution

//there is notting wrong in your layout

Just you forgot to declare the Button there (