app crash due to Invalid column count IllegalArgumentException
Click "Done" button after recording, will meet below exception:
--------- beginning of crash
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.android.soundrecorder, PID: 21475
E AndroidRuntime: java.lang.IllegalArgumentException: Invalid column count(*)
E AndroidRuntime: at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
E AndroidRuntime: at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
E AndroidRuntime: at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
E AndroidRuntime: at android.content.ContentResolver.query(ContentResolver.java:944)
E AndroidRuntime: at android.content.ContentResolver.query(ContentResolver.java:880)
E AndroidRuntime: at android.content.ContentResolver.query(ContentResolver.java:836)
E AndroidRuntime: at com.android.soundrecorder.SoundRecorder.addToPlaylist(SoundRecorder.java:552)
E AndroidRuntime: at com.android.soundrecorder.SoundRecorder.addToMediaDB(SoundRecorder.java:649)
E AndroidRuntime: at com.android.soundrecorder.SoundRecorder.saveSample(SoundRecorder.java:479)
E AndroidRuntime: at com.android.soundrecorder.SoundRecorder.onClick(SoundRecorder.java:420)
Change-Id: I5c77741f49a9b9f37d0c4e6512a9adb5b755f1b7
Signed-off-by: Jindong <jindong.yue@nxp.com>
diff --git a/src/com/android/soundrecorder/SoundRecorder.java b/src/com/android/soundrecorder/SoundRecorder.java
index 3970188..2067d6a 100644
--- a/src/com/android/soundrecorder/SoundRecorder.java
+++ b/src/com/android/soundrecorder/SoundRecorder.java
@@ -533,18 +533,22 @@
* play_order in the playlist.
*/
private void addToPlaylist(ContentResolver resolver, int audioId, long playlistId) {
- String[] cols = new String[] {
+ try {
+ String[] cols = new String[] {
"count(*)"
- };
- Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
- Cursor cur = resolver.query(uri, cols, null, null, null);
- cur.moveToFirst();
- final int base = cur.getInt(0);
- cur.close();
- ContentValues values = new ContentValues();
- values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + audioId));
- values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId);
- resolver.insert(uri, values);
+ };
+ Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
+ Cursor cur = resolver.query(uri, cols, null, null, null);
+ cur.moveToFirst();
+ final int base = cur.getInt(0);
+ cur.close();
+ ContentValues values = new ContentValues();
+ values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + audioId));
+ values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId);
+ resolver.insert(uri, values);
+ } catch (IllegalArgumentException ex) {
+ Log.e(TAG, "Catch IllegalArgumentException: Invalid column count(*)");
+ }
}
/*