I experiment with the table layout using one of the documented examples. With a barebone MainActivity
that just has the following code up to setContentView(R.layout.activity_main)
, the emulator showed the table layout fine. I then added the lines after the setContentView
line and that action caused :
getChildCount()
.@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TableLayout tableLayout = null;
int s = tableLayout.getChildCount();
for(int n = 0; n < s; ++n) {
TableRow row = (TableRow)tableLayout.getChildAt(n);
int t = row.getChildCount();
What have I missed? Thanks for your help in advance.
You have to initialise your TableLayout tableLayout
like this:
TableLayout tableLayout = findViewById(R.id.whatever_id_you_gave_to_the_tablelayout);