This line of code is causing the error. This is what I understood after referring to this link
int c=4;
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT); //this is causing the error
tl.setStretchAllColumns(true);
You need to change it to
TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);