android - Album image cover and java.lang.OutOfMemoryError -


i developing app show album image covers. crashes error:

11-10 18:08:48.148  16187-16187/com.xrobot.andrew.musicalbums e/androidruntime﹕ fatal exception: main     process: com.xrobot.andrew.musicalbums, pid: 16187     java.lang.outofmemoryerror: failed allocate 1459276 byte allocation 421736 free bytes , 411kb until oom             @ dalvik.system.vmruntime.newnonmovablearray(native method)             @ android.graphics.bitmapfactory.nativedecodestream(native method)             @ android.graphics.bitmapfactory.decodestreaminternal(bitmapfactory.java:635)             @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:611)             @ android.graphics.bitmapfactory.decodefile(bitmapfactory.java:391)             @ android.graphics.bitmapfactory.decodefile(bitmapfactory.java:417)             @ android.graphics.drawable.drawable.createfrompath(drawable.java:1230)             @ com.xrobot.andrew.musictest2.songadapter.getview(songadapter.java:73)             @ android.widget.abslistview.obtainview(abslistview.java:2346)             @ android.widget.listview.makeandaddview(listview.java:1875)             @ android.widget.listview.filldown(listview.java:702)             @ android.widget.listview.correcttoolow(listview.java:1484)             @ android.widget.listview.fillgap(listview.java:676)             @ android.widget.abslistview.trackmotionscroll(abslistview.java:5036)             @ android.widget.abslistview$flingrunnable.run(abslistview.java:4584)             @ android.view.choreographer$callbackrecord.run(choreographer.java:858)             @ android.view.choreographer.docallbacks(choreographer.java:670)             @ android.view.choreographer.doframe(choreographer.java:603)             @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:844)             @ android.os.handler.handlecallback(handler.java:746)             @ android.os.handler.dispatchmessage(handler.java:95)             @ android.os.looper.loop(looper.java:148)             @ android.app.activitythread.main(activitythread.java:5443)             @ java.lang.reflect.method.invoke(native method)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:728)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:618) 

partial code in oncreate method:

... while(...){    string thiscover = getcoverartpath(cursor.getlong(6), getapplicationcontext());    songlist.add(new song(thisid, thistitle, thisartist, thispath, thisduration, thiscover)); } songadapter songadt = new songadapter(getapplicationcontext(), songlist); ... 

code use album image cover:

private static string getcoverartpath(long albumid, context context) {     cursor albumcursor = context.getcontentresolver().query(             mediastore.audio.albums.external_content_uri,             new string[]{mediastore.audio.albums.album_art},             mediastore.audio.albums._id + " = ?",             new string[]{long.tostring(albumid)},             null     );     boolean queryresult = albumcursor.movetofirst();     string result = null;     if (queryresult) {         result = albumcursor.getstring(0);     }     albumcursor.close();     return result; } 

layout albumcover :

  <imageview         android:layout_width="50dp"         android:layout_height="50dp"         android:id="@+id/song_cover"         android:scaletype = "fitxy"         android:src="@drawable/note"         android:background="#171717"         android:padding="1dp"         android:layout_marginleft="3dp" /> 

getview in adapter:

@override     public view getview(view convertview, viewgroup parent) {         relativelayout songlay = (relativelayout)songinf.inflate                 (r.layout.song_layout, parent, false);         imageview coverview = (imageview)songlay.findviewbyid(r.id.song_cover);          //get song using position         song currsong = songs.get(position);          if (drawable.createfrompath(currsong.getcover()) != null) {             drawable img = drawable.createfrompath(currsong.getcover());             coverview.setimagedrawable(img);         }          //set position tag         songlay.settag(position);         return songlay;     } 

edit:

i have tryed glide suggested, still same error:

    if (drawable.createfrompath(currsong.getcover()) != null) {         drawable img = drawable.createfrompath(currsong.getcover());         glide.with(mcontext).load("").placeholder(img).override(50,50).into(coverview);     } 

this new error:

11-11 11:05:55.866  11120-11120/com.xrobot.andrew.musicalbumse/androidruntime﹕ fatal exception: main     process: com.xrobot.andrew.musicalbums, pid: 11120     java.lang.outofmemoryerror: outofmemoryerror thrown while trying throw outofmemoryerror; no stack trace available 


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -