Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Code builded ok:
C#
Button buttonCancel = (Button)findViewById(R.id.Cancel);
try{
buttonCancel.setOnClickListener(buttonCancelOnClickListener);
}catch(Exception x)
{
    x.toString();//NullPointerException
}

In text_enter.xml:
HTML
<Button
    android:id="@+id/Cancel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/SendText"
    android:layout_alignBottom="@+id/SendText"
    android:layout_alignParentLeft="true"
    android:text="Cancel" />

buttonCancel = null, why? Please, help.
Posted
Comments
lewax00 25-Nov-12 0:59am    
There's not enough information here to tell, but I'm guessing you are probably trying to get it before it's created. A little more context would help (if I'm right, then specifically which overridden method this is in or called from).

Though you not provide enough information but you can try like this..
Java
private Button buttonCancle;
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wishingpage);

    buttonCancel = (Button)findViewById(R.id.Cancel);

    buttonCancel.setOnClickListener(this);
    }

public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.buttonCancel:
             //do your button work here..you can add more button event using case
        break;
            }
    }
 
Share this answer
 
Solved. I had to
Java
setContentView(R.layout.text_enter);

that contains my Cancel button, before declaring and setting listener for it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900