title: How to solve this Logcat error java.lang.ArithmeticException: divide by zero in android
body: <p>I have been working for dynamically creating table layout but I got log error in my code java.lang.ArithmeticException: divide by zero.
  Code.Where I got error couldn't trigger out from logcat.</p>
  
  <pre><code>  public void servershopimagesoffline() {
       String Specifications = jsonarray;
       try {
           specifi = new JSONArray(Specifications);
  
  
       } catch (JSONException e) {
           e.printStackTrace();
       }
       if (specifi.length() &gt; 0) {
           for (int i = 0; i &lt; specifi.length(); i++) {
               try {
                   specification = specifi.getJSONObject(i);
               } catch (JSONException e) {
                   e.printStackTrace();
               }
               TableLayout ll = (TableLayout) findViewById(R.id.maintable);
  
               // header[i]=new TextView(getApplicationContext());
               try {
                   String type = specification.getString("type");
                   if (type.equalsIgnoreCase("textfield")) {
  
                       String mainheader = specification.getString("main_header");
  
  
  
                       JSONArray fileopt = specification.getJSONArray("field_option");
                       header = new TextView[fileopt.length()];
  
                       for (int j = 0; j &lt; fileopt.length(); j++) {
  
                           JSONObject field = fileopt.getJSONObject(j);
                           row = new TableRow(this);
                           row.setLayoutParams(new TableRow.LayoutParams(
                               ViewGroup.LayoutParams.WRAP_CONTENT,
                               ViewGroup.LayoutParams.WRAP_CONTENT
                           ));
  
                           header[i] = new TextView(getApplicationContext());
                           String fieldoption = field.getString("inside_single_title");
                           LinearLayout.LayoutParams dim = new LinearLayout.LayoutParams(
                               LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                           header[i].setLayoutParams(dim);
                           header[i].setText(fieldoption);
  
                           JSONArray basicopt = field.getJSONArray("basic_opt1");
                           col = new TextView[basicopt.length()];
                           col2 = new TextView[basicopt.length()];
                           row.addView(header[i]);
                           for (int k = 0; k &lt; basicopt.length(); k++) {
                               second = new TableRow(this);
                               second.setLayoutParams(new ViewGroup.LayoutParams(
                                   ViewGroup.LayoutParams.WRAP_CONTENT,
                                   ViewGroup.LayoutParams.WRAP_CONTENT));
                               JSONObject option = basicopt.getJSONObject(k);
                               col[k] = new TextView(getApplicationContext());
                               col2[k] = new TextView(getApplicationContext());
                               col[k].setLayoutParams(dim);
                               col2[k].setLayoutParams(dim);
                               String optnameextra = option.getString("option_name_extra");
                               col[k].setText(optnameextra);
                               String option_desc_extra = option.getString("option_desc_extra");
                               col2[k].setText(option_desc_extra);
                               second.addView(col[k]);
                               second.addView(col2[k]);
  
                               ll.addView(second);
  
  
  
                           }
                           ll.addView(row);
  
  
  
                       }
  
  
                   }
  
               } catch (JSONException e) {
                   e.printStackTrace();
               }
  
  
           }
       }
  
  
   }
  </code></pre>
  
  <p>Logcat Error</p>
  
  <pre><code>05 - 13 12: 10: 21.308 14880 - 14880 / com.journaldev.navigationdrawer E / AndroidRuntime: FATAL EXCEPTION: main
  java.lang.ArithmeticException: divide by zero
  at android.widget.TableLayout.mutateColumnsWidth(TableLayout.java: 583)
  at android.widget.TableLayout.shrinkAndStretchColumns(TableLayout.java: 572)
  at android.widget.TableLayout.measureVertical(TableLayout.java: 470)
  at android.widget.TableLayout.onMeasure(TableLayout.java: 435)
  at android.view.View.measure(View.java: 15172)
  at android.widget.ScrollView.measureChildWithMargins(ScrollView.java: 1196)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java: 310)
  at android.widget.ScrollView.onMeasure(ScrollView.java: 318)
  at android.view.View.measure(View.java: 15172)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java: 4814)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java: 1390)
  at android.widget.LinearLayout.measureHorizontal(LinearLayout.java: 1038)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java: 576)
  at android.view.View.measure(View.java: 15172)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java: 4814)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java: 310)
  at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java: 124)
  at android.view.View.measure(View.java: 15172)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java: 4814)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java: 1390)
  at android.widget.LinearLayout.measureVertical(LinearLayout.java: 681)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java: 574)
  at android.view.View.measure(View.java: 15172)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java: 4814)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java: 310)
  at android.view.View.measure(View.java: 15172)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java: 4814)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java: 1390)
  at android.widget.LinearLayout.measureVertical(LinearLayout.java: 681)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java: 574)
  at android.view.View.measure(View.java: 15172)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java: 4814)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java: 310)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java: 2148)
  at android.view.View.measure(View.java: 15172)
  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java: 1848)
  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java: 1100)
  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java: 1273)
  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java: 998)
  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java: 4212)
  at android.view.Choreographer$CallbackRecord.run(Choreographer.java: 725)
  at android.view.Choreographer.doCallbacks(Choreographer.java: 555)
  at android.view.Choreographer.doFrame(Choreographer.java: 525)
  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java: 711)
  at android.os.Handler.handleCallback(Handler.java: 615)
  at android.os.Handler.dispatchMessage(Handler.java: 92)
  at android.os.Looper.loop(Looper.java: 137)
  at android.app.ActivityThread.main(ActivityThread.java: 4745)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java: 511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 786)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 553)
  at dalvik.system.NativeStart.main(Native Method)
  05 - 13 12: 15: 21.336 14880 - 14880 / com.journaldev.navigationdrawer I / Process: Sending signal.PID: 14880 SIG: 9
  </code></pre>