title: Adding double values to a TableModel in java
body: <p>I have written a table model using <code>AbstractTableModel</code> as below.</p>
  
  <pre><code>class DataTableModel extends AbstractTableModel {
  
      /** The table. */
      private DataTable table;
  
      /** The Constant LOGGER. */
      static final Logger LOGGER = Logger.getLogger(DataTableModel.class);
  
      /**
       * Instantiates a new data table model.
       * 
       * @param ptable
       *            the table
       */
      public DataTableModel(final DataTable ptable) {
          this.table = ptable;
      }
  
      /**
       * Adds table model listener.
       * 
       * @param arg0
       *            the arg0
       */
      @Override
      public void addTableModelListener(final TableModelListener arg0) {
      }
  
      /**
       * Gets column class.
       * 
       * @param col
       *            the col
       * @return the column class
       */
      @Override
      public Class&lt;?&gt; getColumnClass(final int col) {
          return table.getColumns().get(col).getTypeClass();
  
      }
  
      /**
       * Gets column count.
       * 
       * @return the column count
       */
      @Override
      public int getColumnCount() {
          return table.getColumns().size();
      }
  
      /**
       * Gets column name by column index.
       * 
       * @param columnIndex
       *            the column index
       * @return the column name
       */
      @Override
      public String getColumnName(final int columnIndex) {
          HashList&lt;ColumnDefinition&gt; columns = table.getColumns();
          String columnName = columns.getColumnName(columnIndex);
          return (columnName + " (" + columns.get(columnName).getType() + ")");
      }
  
      /**
       * Gets row count.
       * 
       * @return the row count
       */
      @Override
      public int getRowCount() {
          return table.getRowCount();
      }
  
      /**
       * Gets value at given cell.
       * 
       * @param row
       *            the row
       * @param col
       *            the col
       * @return the value at
       */
      @Override
      public Object getValueAt(final int row, final int col) {
          if (table.getColumns().get(col).getType() == TypeEnum.Boolean) {
              if (table.get(row, col) != null
                      &amp;&amp; "true".equalsIgnoreCase(table.get(row, col))) {
                  return Boolean.TRUE;
              }
  
              return Boolean.FALSE;
          } else if (table.getColumns().get(col).getType() == TypeEnum.Double) {
              try {
                  String r = this.table.get(row, col);
                  return r;
                  Object obj = row.get(col);
  
                  if (row == null) {
                      return null;
                  }
  
                  return obj;
              } catch (IndexOutOfBoundsException e) {
                  return null;
              }
          }
  
          return table.get(row, col);
      }
  
      /**
       * Gets whether the given cell is editable.
       * 
       * @param arg0
       *            the arg0
       * @param arg1
       *            the arg1
       * @return true, if is cell editable
       */
      @Override
      public boolean isCellEditable(final int arg0, final int arg1) {
          System.out.println("=========isCellEditable=========");
          return true;
      }
  
      /**
       * Removes table model listener.
       * 
       * @param arg0
       *            the arg0
       */
      @Override
          public void removeTableModelListener(final TableModelListener arg0) {
      }
  
      /**
       * Sets given value at given cell.
       * 
       * @param value
       *            the value
       * @param row
       *            the row
       * @param col
       *            the col
       */
      @Override
      public void setValueAt(final Object value, final int row, final int col) {
          if (table.getColumns().get(col).getType() == TypeEnum.Boolean) {
              if (value instanceof Boolean
                      &amp;&amp; ((Boolean) value).booleanValue() == Boolean.TRUE) {
                  table.setValue(row, col, "true");
                  LOGGER.info("true " + value.toString());
              } else {
                  LOGGER.info("true " + value.toString());
                  table.setValue(row, col, "false");
              }
          } else if(table.getColumns().get(col).getType()==TypeEnum.Double){
              table.setValue(row, col, String.valueOf(value));
          } else {
              if (value != null) {
                  table.setValue(row, col, value.toString());
              }
          }
  
          fireTableCellUpdated(row, col);
      }
  </code></pre>
  
  <p>when I am adding double values to a table cell it gives an exception </p>
  
  <pre><code>"Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Cannot format given Object as a Number."
  </code></pre>
  
  <p>Please help me to solve this.
  Thank You</p>