Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android getting error while displaying image from url

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;
        }       
    }
like image 235
atluriajith Avatar asked Jul 23 '26 17:07

atluriajith


1 Answers

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)
{}
like image 192
Mohammed Azharuddin Shaikh Avatar answered Jul 25 '26 07:07

Mohammed Azharuddin Shaikh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!