• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Problem with TableRow (Please Help)

ramesh_bh

Newbie
Sep 16, 2010
17
1
Hi,

My requirement is like i have to display multiple rows, and each row should contain three buttons as columns.
here is my code :

TableLayout contactLayout;
TableRow tr[] = null;
Button b1 = null;
Button b2 = null;
Button b3 = null;

contactLayout = (TableLayout) findViewById(R.id.ContactsLayout);

for (int i = 0; i < 10; i++) {

b1= new Button(this);
b2 = new Button(this);
b3= new Button(this);

tr = new TableRow(this);
b1.setText("Ramesh");
b2.setText("R@infy.com");
b3.setText("9591504000");
tr.addView(b1, new TableRow.LayoutParams(1));
tr.addView(b2, new TableRow.LayoutParams(2));
tr.addView(b3, new TableRow.LayoutParams(3));
contactLayout.addView(tr, new TableLayout.LayoutParams());

}

But after running the application, i got null pointer exception at tr = new TableRow(this);
Can any one help me to solve this,
If any similar example providing can also be useful to me.
Please Respond.

Ramesh BH
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones