当我尝试为我创建的按钮实现 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;
}
}