Note that there are some explanatory texts on larger screens.

plurals
  1. POSave data with Image from server to SQLite database and then show it on list view in Android
    primarykey
    data
    text
    <p>I read so many blogs and tutorial but I didn't get the right answer.I am working on My requirement is that I have a url by which I am getting data in the form of xml. Inside Async task I am parsing the data successfully.Then I have to save data to SQLite database then again I will fetch data from database and show it on screen.But showing blank image so I am getting problem. Doing XML parsing-</p> <pre><code>XMLParser parser = new XMLParser(); String xml = parser.getXmlFromUrl(url); //getting XML from URL Document doc = parser.getDomElement(xml); //getting DOM element NodeList nl = doc.getElementsByTagName(PRODUCT); for (int i = 0; i &lt; nl.getLength(); i++) { Element e = (Element) nl.item(i); String name=parser.getValue(e, PRODUCT_NAME); String image_url=parser.getValue(e, PRODUCT_IMAGE); //Changing image to byte[] type because here I am getting image url byte[] logoImage = getLogoImage(image_url); //Inserting data in database mySQLiteAdapter.insert_img_Info(name, logoImage); } // Changing image to byte[] using url public byte[] getLogoImage(String url) { try { URL imageUrl = new URL(url); URLConnection ucon = imageUrl.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(500); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } photo = baf.toByteArray(); } catch (Exception e) { Log.d("ImageManager", "Error: " + e.toString()); } return photo; } /* Here data is also inserting successfully in SQLite db.But when I am fetching image from database and setting image on ImageView It's not showing any thing*/ mySQLiteAdapter = new DataBaseHelper(this); //fetching data to cursor Cursor c1 = mySQLiteAdapter.read_img_info(); if (c1 != null) { if (c1.moveToNext()) { do { name=c1.getString(c1.getColumnIndex("NAME")); Getting Image from cursor img=c1.getBlob(c1.getColumnIndex("MYIMG")); Log.i(TAG, "Image.length="+img.length); //Here I am getting image length for all images successfully } while (c1.moveToNext()); } //Here in bt it's coming null //converting data to Bitmap Bitmap bt = BitmapFactory.decodeByteArray(img, 0, img.length); ImageView img1 = (ImageView) findViewById(R.id.imgPhoto); img1.setImageBitmap(bt); } //My DatabaseHelper class having code public static final String TB_MYIMAGE = "MyImage"; for c creating table private static final String CREATE_DEMO = "CREATE TABLE IF NOT EXISTS " + TB_MYIMAGE + "(NAME VARCHAR(20),MYIMG BLOB NOT NULL);"; // insert record into table public void insert_img_Info(String name,byte[] logoImage) { myDataBase.execSQL("INSERT INTO "+"'"+TB_MYIMAGE+"'"+ " (NAME,MYIMG) Values ('" + name + "','"+logoImage+"');"); // get data from table public Cursor read_img_info() { Cursor c = myDataBase.rawQuery("SELECT NAME,MYIMG FROM MyImage",null); if (c != null) { return c; } else { return null; } } </code></pre> <p>So please can any body help me.I am doing this for offline scenario based application.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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