3

When i'm displaying image from url with using below code, application is taking too much time to load images from server. Application is hanging up if we have 8-10 images to load.

Bitmap mbmp = BitmapFactory.decodeStream(new java.net.URL("urlname").openStream());
Imageview_ref.setImageBitmap(mbmp);

and getting this in Logcat

09-15 11:34:14.265: ERROR/Cursor(14443): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.UserLogin/databases/sample.db, table = null, query = SELECT LocationName , LocationImage FROM Locationlist
09-15 11:34:14.265: ERROR/Cursor(14443): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
09-15 11:34:14.265: ERROR/Cursor(14443):     at com.UserLogin.FindPlaces.getallLocs(FindPlaces.java:134)
09-15 11:34:14.265: ERROR/Cursor(14443):     at com.UserLogin.FindPlaces.onCreate(FindPlaces.java:37)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.view.View.performClick(View.java:2408)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.view.View$PerformClick.run(View.java:8816)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.os.Handler.handleCallback(Handler.java:587)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.os.Looper.loop(Looper.java:123)
09-15 11:34:14.265: ERROR/Cursor(14443):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-15 11:34:14.265: ERROR/Cursor(14443):     at java.lang.reflect.Method.invokeNative(Native Method)
09-15 11:34:14.265: ERROR/Cursor(14443):     at java.lang.reflect.Method.invoke(Method.java:521)
09-15 11:34:14.265: ERROR/Cursor(14443):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-15 11:34:14.265: ERROR/Cursor(14443):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-15 11:34:14.265: ERROR/Cursor(14443):     at dalvik.system.NativeStart.main(Native Method)

with this logcat error message i'm still getting output.

this is my updated code view..

public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            View v = convertView;
            if(v == null){
                LayoutInflater vl = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vl.inflate(R.layout.placeslist, null);
            }
            Fields o = results.get(position);

            if (o != null) {
                TextView iv = (TextView)v.findViewById(R.id.toptext);
                ImageView tv_Image = (ImageView)v.findViewById(R.id.Locimage);

                iv.setText(o.getLocationName());                            

                try {
                    Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(o.getLocationImage()).getContent());
                    tv_Image.setImageBitmap(bitmap);
                } catch (Exception e) {
                    e.printStackTrace();
                }


            }
            return v;
        }       
    }

2 Answers 2

3

logcat shows that you are not closing your cursor and database

onDestroy() method of your activity, add this

try{
   cursor.close();
   db.close(); 
}catch(exception e)
{}
Sign up to request clarification or add additional context in comments.

1 Comment

shall i close it by overriding application onDestroy method. How to close cursor.
1

Please try this ::

            try {
        Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
                "http://xyz.com/a/f/a.png")
                .getContent());
        tran_btn_skip.setImageBitmap(bitmap);
    } catch (Exception e) {
    }

Make sure you have to give permission of Internet

5 Comments

thanks Nik. we can use this piece of code for all type of images right?, and are you sure with this code image will load from server?
Nic.. its working fine, but for one image. i'm getting this message in logcat and image is not displaying..::: 09-15 12:28:47.886: DEBUG/skia(26484): --- decoder->decode returned false :::
print Fields o in logcat and tell me what you get
url is coming fine but the image is not displaying in view
so you cant show image in it please try device it get successfully

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.