title: Android contentResolver insert not working
body: <p>I would appreciate some help in a problem. I'm trying to add songs to a playlist, but whenever I try to use either insert or bulkInsert, it does not work,
  if I use insert I'll just get a null row as a return value, if I use bulkInsert it will throw a NullPointerException, ( so that basically means that no rows have been inserted, because bulkInsert returns the number of inserted rows )
  Below I have the code I used, and a snap of the state of my method when I was debugging it:</p>
  <pre><code> public void savePlaylist(Playlist p) {
  
      String name = p.getPlaylistName();
      Uri playlistURI = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
      ContentResolver contentResolver = context.getContentResolver();
      Cursor playlistCursor = contentResolver.query(playlistURI, new String[]{&quot;*&quot;}, null, null, null);
      long playlistID = getPlaylistID(playlistCursor, name);
  
  
      if (playlistID == 0)
  
      {
          ContentValues playlistValue = new ContentValues();
          playlistValue.put(MediaStore.Audio.Playlists.NAME, name);
          playlistValue.put(MediaStore.Audio.Playlists.DATE_MODIFIED, System.currentTimeMillis());
          contentResolver.insert(playlistURI, playlistValue);
          playlistID = getPlaylistID(contentResolver.query(playlistURI, new String[]{&quot;*&quot;}, null, null, null), name);
      }
  
      Uri insertionUri = MediaStore.Audio.Playlists.Members.getContentUri(&quot;external&quot;, playlistID);
  
      ContentValues[] rowsToAdd = new ContentValues[p.getSongs().size()];
  
      for (int i = 0; i &lt; p.getSongs().size(); i++) {
          Song toAdd = p.getSongs().get(i);
          rowsToAdd[i] = new ContentValues();
          rowsToAdd[i].put(MediaStore.Audio.Playlists.Members.AUDIO_ID, toAdd.getId());
  
      }
  
       try {
          int result = context.getContentResolver().bulkInsert(insertionUri, rowsToAdd);
  
          if (result &gt; 0) {
              Log.d(&quot;DEBUG&quot;, &quot;Row inserted succesfully&quot;);
          }
      }
      catch (Exception ex)
      {
          ex.printStackTrace();
      }
  }
  </code></pre>
  <p>I should specify, this method is used to Add a playlist if it does not exist, and add songs to it if it does, before I start handling events like if songs already exist or not, I should fix this problem first.</p>
  <p><a href="https://i.stack.imgur.com/xD4z0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xD4z0.png" alt="Snap from when debugging, up to the point I am calling bulkInsert" /></a></p>