Hello and sorry for my english skills =)
I'm coding a little calculation programm in Android Studio and have a problem.
I've made dynamically creating TableRow's in TableLayout like this:
TableLayout table2 = (TableLayout) findViewById(R.id.table2);
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL);
TableRow row = new TableRow(this);
row.setLayoutParams(rowParams);
row.addView(floor2);
row.addView(ps2table);
row.addView(gsatable);
row.addView(vitable);
table2.addView(row);
Where floor2, ps2table, gsatable and vitable - are TextView's which calculating after a button is pressed.
After the Table has created i try to use one of the numbers (the last row of the TableLayout and the child at 2 position):
int gsn_count = table2.getChildCount();
TableRow gsnRow = (TableRow) table2.getChildAt(gsn_count);
TextView tGsn = (TextView) gsnRow.getChildAt(2);
My problem is, when i try to take a value of one or another number (double) from any TableRow from this TableLayout
, i got this error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.TableRow.getChildAt(int)' on a null object reference
It is look for me as i have not a number in place which i refer to, but it is there. I'll add a picture with comments and all my code in links below.
Picture: https://i.stack.imgur.com/erfaL.png
Code for a method in which i've got an error: http://pastebin.com/nDPnbHNR
Thank you!