Reputation: 37
my app crashes with this code.. it doesnt even start up.. any ideas guys thanks my app crashes with this code.. it doesnt even start up.. any ideas guys thanks
package com.about.bysk;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.Toast;
public abstract class AboutActivity extends Activity implements
OnItemSelectedListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spin);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Toast.makeText(null, "a", 5);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
}
this makes my app crash. please help..
Upvotes: 0
Views: 1952
Reputation: 15701
you have not set the lisnter to spinner
as per you code do as below ...
1-public class AboutActivity extends Activity implement OnItemSelectedListener
{
2- spinner.setOnItemSelectedListener(this)
;
3- Toast.makeText(AboutActivity.this,"RootBox",Toast.LENGTH_LONG).show()
;
you can't pass null as context to Toast
Toast.makeText(AboutActivity.this, "a", Toast.LENGTH_LONG).show();
Upvotes: 0
Reputation: 33505
You have to set Listener
for your spinner and your class must implement OnItemSelectedListener
public class YourClass extends Activity implements OnItemSelectedListener { ... }
Then you must set Listener
for your spinner:
spinner.setOnItemSelectedListener(this);
Or you can use it like anonymous class
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { ... }
@Override
public void onNothingSelected(AdapterView<?> parentView) { ... }
});
Note: If you want to show Toast, you must call show()
method.
Upvotes: 1
Reputation: 1577
You forgot to setlistner ... Also you din call show method with toast !!
Upvotes: 0