Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read image files from the gallery of the phone
    text
    copied!<p>I have a problem with this code, in practice i'm trying to read from the gallery of the phone only the file name image2.jpg image3.jpg ... etc. but this code gives me error </p> <p>this is the Code:</p> <pre><code> public static Uri getRandomImage(ContentResolver resolver) { String secondo = "image2.jpg"; String terzo = "image3.jpg"; String quarto = "image4.jpg"; String quinto = "image5.jpg"; String sesto = "image6.jpg"; String settimo = "image7.jpg"; String ottavo = "image8.jpg"; String[] projection = new String[] { BaseColumns._ID, MediaColumns.DATA, }; Uri uri = Media.EXTERNAL_CONTENT_URI; Cursor cursor = Media.query(resolver, uri, projection, null, MediaColumns._ID); if (cursor == null || cursor.getCount() &lt;= 0) { return null; } cursor.moveToPosition(new Random().nextInt(cursor.getCount())); String completefilepath = cursor.getString(cursor.getColumnIndex(MediaColumns.DATA)); if(completefilepath == secondo || completefilepath == terzo || completefilepath == quarto || completefilepath == quinto || completefilepath == sesto || completefilepath == settimo || completefilepath == ottavo){ string = cursor.getString(1); } return Uri.withAppendedPath(uri, string); } </code></pre> <p>this is the LOGCAT:</p> <pre><code>E/AndroidRuntime(9147): FATAL EXCEPTION: main E/AndroidRuntime(9147): java.lang.IllegalStateException: Unknown URL: content://media/external/images/media/null E/AndroidRuntime(9147): at android.os.Parcel.readException(Parcel.java:1268) E/AndroidRuntime(9147): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160) E/AndroidRuntime(9147): at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:125) E/AndroidRuntime(9147): at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:538) E/AndroidRuntime(9147): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:467) E/AndroidRuntime(9147): at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:380) E/AndroidRuntime(9147): at it.bisemanuDEV.slidepuzzle.TileView.getImageFromUri(TileView.java:559) E/AndroidRuntime(9147): at it.bisemanuDEV.slidepuzzle.TileView.newGame(TileView.java:156) E/AndroidRuntime(9147): at it.bisemanuDEV.slidepuzzle.SlidePuzzleActivity.onOptionsItemSelected(SlidePuzzleActivity.java:377) E/AndroidRuntime(9147): at android.app.Activity.onMenuItemSelected(Activity.java:2762) E/AndroidRuntime(9147): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730) E/AndroidRuntime(9147): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143) E/AndroidRuntime(9147): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855) E/AndroidRuntime(9147): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532) E/AndroidRuntime(9147): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122) E/AndroidRuntime(9147): at android.view.View$PerformClick.run(View.java:8819) E/AndroidRuntime(9147): at android.os.Handler.handleCallback(Handler.java:603) E/AndroidRuntime(9147): at android.os.Handler.dispatchMessage(Handler.java:92) E/AndroidRuntime(9147): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime(9147): at android.app.ActivityThread.main(ActivityThread.java:4627) E/AndroidRuntime(9147): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(9147): at java.lang.reflect.Method.invoke(Method.java:521) E/AndroidRuntime(9147): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) E/AndroidRuntime(9147): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) E/AndroidRuntime(9147): at dalvik.system.NativeStart.main(Native Method) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload