title: ArithmeticException: Divide by zero with table layout dynamically in Android
body: <p>I want to display 14 columns of an SQLite database in a table layout dynamically at run time. I have tried lots of, but when I run the app it crashes and I'm getting ArithmeticException: divide by zero and error for mutateColumnsWidth.</p>
  
  <p>Here is my Activity code:</p>
  
  <pre><code>SQLiteDatabase sqlDatabase = databaseHelper.getWritableDatabase();
  Cursor c1 =sqlDatabase.rawQuery(performanceQuery , null);
  
  int rows = c1.getCount();
  Log.e("rows "," = " + rows);
  
  int cols = c1.getColumnCount();
  Log.e("cols "," = " + cols);
  
  //Cursor c1 =db.rawQuery(query, null);
  if (c1 != null &amp;&amp; c1.getCount() != 0) 
  {  
      Log.e("11111","11111");
      if (c1.moveToFirst())
      {   
          Log.e("222222","222222");
          // outer for loop
          for (int i = 0; i &lt; rows; i++) 
          {
              TableRow row = new TableRow(this);
              row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                  LayoutParams.WRAP_CONTENT));
  
              // inner for loop
              for (int j = 0; j &lt; cols; j++)
              {
                  TextView tv = new TextView(this);
                  tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                  tv.setBackgroundResource(R.drawable.cell_shape);
                  tv.setGravity(Gravity.CENTER);
                  tv.setTextSize(18);
                  // tv.setTextColor(010101);
                  tv.setPadding(5, 5, 5, 5);
                  tv.setText(c1.getString(j));
  
                  String strText = tv.getText().toString().trim();
                  System.out.println(" strText " + strText);
  
                  row.addView(tv);
              }
              Log.e("3333333","3333333");
              c1.moveToNext();
  
              Log.e("4444444","4444444");
              table_layout.addView(row);
          }
      }
      sqlDatabase.close();
      c1.close();
      Log.e("55555555","55555555");
  }
  </code></pre>
  
  <p>Here is .xml code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="@android:color/white"
      android:padding="5dp" &gt;
  
     &lt;TableLayout
          android:id="@+id/tableLayout_PerformanceReport"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/textTitle"
          android:background="@android:color/white"
          android:padding="10dp"
          android:shrinkColumns="*"
          android:stretchColumns="*" 
          android:scrollbars="vertical|horizontal"
          android:scrollbarAlwaysDrawVerticalTrack="true"&gt;
      &lt;/TableLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Log error Information:</p>
  
  <pre><code>07-11 12:58:05.530: E/AndroidRuntime(1264): FATAL EXCEPTION: main
  07-11 12:58:05.530: E/AndroidRuntime(1264): java.lang.ArithmeticException: divide by zero
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.widget.TableLayout.mutateColumnsWidth(TableLayout.java:579)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.widget.TableLayout.shrinkAndStretchColumns(TableLayout.java:568)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.widget.TableLayout.measureVertical(TableLayout.java:466)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.widget.TableLayout.onMeasure(TableLayout.java:431)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.view.View.measure(View.java:8313)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.view.View.measure(View.java:8313)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.view.View.measure(View.java:8313)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.view.View.measure(View.java:8313)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.os.Handler.dispatchMessage(Handler.java:99)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.os.Looper.loop(Looper.java:123)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at android.app.ActivityThread.main(ActivityThread.java:3683)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at java.lang.reflect.Method.invokeNative(Native Method)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at java.lang.reflect.Method.invoke(Method.java:507)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  07-11 12:58:05.530: E/AndroidRuntime(1264):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>