如果我为另一个按钮显示相同的东西,我的代码意外停止

时间:2013-09-14 17:28:46

标签: android

我在forloop中获取日期并仅在button.text中显示最后一天的部分日期并显示日期的完整值,当点击Toast prblem中的按钮时,它只适用于1个按钮,如果我做同样的进程代码意外停止为什么只有Sun2值显示为什么不显示Mon2值?帮助我代码中的错误是什么?我想在Toast上显示每个buttonlast 2值和完整值

   public class MainActivity extends Activity implements View.OnClickListener {

Calendar calendarGlobal;
   int currentweekno = 0;

static Button e00;
static Button e01;
static Button e02;
  static Button e03;
static Button e04;
static Button e05;
static Button e06;



String value;
String[] days = new String[7];

static TextView txt1;






@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    e00 = (Button) findViewById(R.id.e00);
    e01 = (Button) findViewById(R.id.e01);
    e02 = (Button) findViewById(R.id.e02);
    e03 = (Button) findViewById(R.id.e03);
    e04 = (Button) findViewById(R.id.e04);
    e05 = (Button) findViewById(R.id.e05);
    e06 = (Button) findViewById(R.id.e06);

     e00.setOnClickListener(this);
    e01.setOnClickListener(this);
     e02.setOnClickListener(this);

    e03.setOnClickListener(this);
    e04.setOnClickListener(this);
    e05.setOnClickListener(this);
    e06.setOnClickListener(this);


    txt1 = (TextView) findViewById(R.id.textview1);

     Calendar mCalendar = Calendar.getInstance();

    Log.d("Current Week:", "" + mCalendar.get(Calendar.WEEK_OF_YEAR));


    calculateWeek(currentweekno);

}

public void calculateWeek(int currentweekno) {

     calendarGlobal = Calendar.getInstance();
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    calendarGlobal.add(Calendar.WEEK_OF_YEAR, +currentweekno);
    calendarGlobal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

    for (int i = 0; i < 7; i++) {
        days[i] = df.format(calendarGlobal.getTime());
        String[] Sun = days[0].split("/");


        String Sun2 = Sun[Sun.length-1];



          e00.setText(Sun2);
          e00.setTag(days[0]);

        // String[] Mon = days[1].split("/");


         // String Mon2 = Mon[Mon.length-1];




     //  e01.setText(Mon2);
         e01.setTag(days[1]);

        e02.setText("01");
        e02.setTag(days[2]);

        e03.setText("01");
        e03.setTag(days[3]);

        e04.setText("01");
        e04.setTag(days[4]);

        e05.setText("01");
        e05.setTag(days[5]);

        e06.setText("01");
        e06.setTag(days[6]);
        calendarGlobal.add(Calendar.DATE, 1);
    }

}
@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.e00:

     value = e00.getTag().toString();
     Toast.makeText(this, value, Toast.LENGTH_SHORT).show();

        break;
    case R.id.e01:


      value = e01.getTag().toString();
     Toast.makeText(this, value, Toast.LENGTH_SHORT).show();

        break;

    case R.id.e02:
        // do stuff;
        value = e02.getTag().toString();

        Toast.makeText(this, value, Toast.LENGTH_SHORT)
        .show();


        break;
    case R.id.e03:

        value = e03.getTag().toString();

        Toast.makeText(this, value, Toast.LENGTH_SHORT)
        .show();

        break;

    case R.id.e04:

        value = e04.getTag().toString();
        Toast.makeText(this, value, Toast.LENGTH_SHORT).show();

        break;
    case R.id.e05:

        value = e05.getText().toString();
        Toast.makeText(this, value, Toast.LENGTH_SHORT) .show();

        break;
    case R.id.e06:

        value = e06.getText().toString();
        Toast.makeText(this, value, Toast.LENGTH_SHORT) .show();

        break;

    }

}


  }


      error show on log  "Caused by: java.lang.NullPointerException"

0 个答案:

没有答案