这是发送数据的方法。
public void commitData(View v) {
Bundle bundle=new Bundle();
bundle.putString("key", spinner.getItemAtPosition(spinner.getSelectedItemPosition()).toString());
// String selection = spinner.getSelectedItem().toString();
Intent alarmSet = new Intent(getApplicationContext(), ViewOffense.class);
alarmSet.putExtras(bundle);
startActivityForResult(alarmSet, 0);
}
这是接收数据的方法
public class ViewOffense extends Activity {
EditOffense eo=new EditOffense();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.viewoffense);
Bundle bundle=this.getIntent().getExtras();
if(bundle != null){
String selection=bundle.getString("key");
TextView textview=(TextView)findViewById(R.id.textview);
textview.setText(selection);
}
else{
Toast.makeText(ViewOffense.this,"Haven't Received any data yet", Toast.LENGTH_LONG).show();
}
}
我不断收到空指针异常。