private int doAddOrEdit = 1;

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addmodel);
        Bundle bun = this.getIntent().getExtras();
        doAddOrEdit = bun.getInt("which");      //bun空指针异常,但明明有定义啊。
        ...
        }

解决方案 »

  1.   

    你切换过来的时候往extras里面放bundle了吗?
      

  2.   

    必须有啊                                Bundle data = new Bundle();
    data.putInt("which",1);
    Intent intent = new Intent(Model.this,AddModel.class);
    intent.putExtras(intent);
    startActivity(intent);
      

  3.   

     intent.putExtras(intent);//放的是intent,不是bundle的data............所以还是没传。