1. Check out our companion app, Forums for Android! Download from Google Play

Problem with TableRow (Please Help)

Discussion in 'Android Apps & Games' started by ramesh_bh, Oct 7, 2010.

  1. ramesh_bh

    ramesh_bh Member
    Thread Starter
    16

    Sep 16, 2010
    17
    1
    16
    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
     

    Advertisement

Share This Page

Loading...