當我嘗試爲我創建的按鈕實現onclicklistener時,我不斷收到空指針異常。onclicklistener爲按鈕數組提供空指針
Button setHighBtn[] = null;
Button setLowBtn[]=null;
TextView tv[] = new TextView[oNumber];
for (int i=0;i<oNumber;i++){
tv[i] = new TextView(this);
tv[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv[i].setText(oName[i]);
tv[i].setTextSize(20);
//tv[i].setLayoutParam)
layout.addView(tv[i]);
if (capability[i]==0){
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.full_capabilities, layout);
setHighBtn[i]=(Button)findViewById(R.id.setHigh);
setHighBtn[i]=(Button)findViewById(R.id.setLow);
setHighBtn[i].setOnClickListener(this);
setLowBtn[i].setOnClickListener(this);
}else{
setHighBtn[i]=null;
setLowBtn[i]=null;
}
}
雅你的權利。我的錯。 – zms6445 2012-08-14 22:22:11
很高興我能幫到你:) – iTurki 2012-08-14 22:22:48