title: SQLiteMisuseException: error code 21 when inserting a row
body: <p>I sometimes get SQLiteMisuseException when row is being inserted. Application works perfectly on hundreds of devices but on one with android 3.1 there is an SQLite exception.
  Stack trace:</p>
  
  <pre><code>    android.database.sqlite.SQLiteMisuseException: error code 21: not an error
      at android.database.sqlite.SQLiteStatement.native_executeInsert(Native Method)
      at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:112)
  </code></pre>
  
  <p>This is a code which invoking executeInsert():</p>
  
  <pre><code>    final SQLiteStatement insUrlStmt = db.compileStatement("insert into urls (url,idx) values (?,?)");
      insUrlStmt.bindString(1, url)
      insUrlStmt.bindLong(2, idx);
      return insUrlStmt.executeInsert();
  </code></pre>
  
  <p>Declaration of db field:</p>
  
  <pre><code>    private final SQLiteDatabase db;
  </code></pre>
  
  <p>Initialization of db field (this is invoked once in onCreate() of Application class object) and reference to DataHelper is stored statically in application instance:</p>
  
  <pre><code>    public DataHelper(Context context) {db = new OpenHelper(context).getWritableDatabase();   }
  </code></pre>
  
  <p>OpenHelper constructor:</p>
  
  <pre><code>    protected OpenHelper(Context context) 
  {
       super(context, "database.db", null, 1);       
  }
  </code></pre>
  
  <p>I've already read this question: <a href="https://stackoverflow.com/questions/5285456/android-sqlite-error-code-21">Android SQLite error code 21</a> and searched for things mentioned there.</p>
  
  <p>SQLiteDatabase (db field) is opened only once and it is never closed directly from application code. Multi-thread access should not be a problem because first thing in executeInsert() method is locking database (I checked in source code of android 2.1, so I assume that this behavior didn't changed in 3.1).</p>