Andrew
Andrew

Reputation: 37

Application crashing on startup due to click listener?

This code which compiles fine seems to crash my application at startup

private OnClickListener teamlisten = new OnClickListener() {
     public void onClick(View v) {
      getListView().setVisibility(View.GONE);
  }
}; 
 //this is in OnCreate
Button teambtn = (Button)findViewById(R.id.teams);
teambtn.setOnClickListener(teamlisten);

Any help is appreciated.

Thanks, Andrew

Upvotes: 0

Views: 255

Answers (2)

Falmarri
Falmarri

Reputation: 48577

You have some conflicting issues here. You say you use

Button teambtn = (Button)findViewById(R.id.teams);

but later you also have

getListView().setVisibility(View.GONE);

Those 2 things don't make sense together. Either you have a listactivity, in which you haven't called setContentView and thuse you can't call findViewById(). Or you're overriding a regular activity with your own listview, but then you don't have the getListView() method.

Do you understand now why we need more code to help you? You didn't even post a stacktrace.

Upvotes: 1

Karudosu
Karudosu

Reputation: 89

try:

    ((Button)findViewById(R.id.teams)).setOnClickListener(new OnClickListener() {
     public void onClick(View v) {
         getListView().setVisibility(View.GONE);
     }
   });

Maybe this will not help but who knows. if it doesn't work, give more details ! :)

Upvotes: 0

Related Questions