Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7418781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:56:48+00:00 2026-05-29T07:56:48+00:00

I want to display images stored in my database,however my program is throwing an

  • 0

I want to display images stored in my database,however my program is throwing an exception(CursorIndexOutOfBoundsException: Index -1 requested, with a size of 100).
I’m using this and in this tutorial I have managed to insert the images into the database but retreiving them is the problem.
Trying to find answers from google and StackOverflow,I have also come across the following questions.
Qustion1
Qustion2.However these questions do not help my case.Any help would be grateful.

Below is my code.

    db = helper.getWritableDatabase();      
    //select the data
    //while(cursor.moveToFirst());
     cursor = db.query(DBHelper.TABLE, new String[] {DBHelper.C_PHOTOS },
                 null, null, null, null, null);

    //get it as a ByteArray
    byte[] imageByteArray=cursor.getBlob(1);
    //the cursor is not needed anymore
    cursor.close();
     
    //convert it back to an image
    ByteArrayInputStream imageStream = new ByteArrayInputStream(imageByteArray);
    Bitmap theImage = BitmapFactory.decodeStream(imageStream);

Here is the clase which inserts the images

       URL url = new URL("myurl");
             URLConnection ucon = url.openConnection();
             InputStream is = ucon.getInputStream();
             BufferedInputStream bis = new BufferedInputStream(is,128);
             ByteArrayBuffer baf = new ByteArrayBuffer(128);
             int current = 0;
             while ((current = bis.read()) != -1) {
                     baf.append((byte) current);
             }
            ContentValues v = new ContentValues();          
            v.put(DBHelper.C_PHOTOS,baf.toByteArray());
            v.put(DBHelper.C_PHOTOS, photoThumbnailUrl);
            db.insert(DBHelper.TABLE, null, v);

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:56:49+00:00Added an answer on May 29, 2026 at 7:56 am

    Try this:

    byte[] imageByteArray = cursor.getBlob(cursor.getColumnIndex(DBHelper.C_PHOTOS));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to retrieve image stored in mysql as path using php and display
I want to display images on a .net page which I load from database
I want to display calendar with some notes/events which i stored in database. In
I am using asp.net 4.0 and all my images are stored in database using
I am parsing the public timeline xml from twitter and want to display images
Just looking for a good PHP Image Library, I want to display images with
I want to display about 5-8 images on my page, one by one, but
I want to integrate the Cover Flow for the images display in my iPhone
I have some text/images that I only want to display in the normal state
I have a list of images which I want to display in a page.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.