Android getDrawable() from inside a Fragment -


i have fragment following code:

final myactivity activity = (myactivity )getactivity(); 

and bit later:

drawable d = (drawable) ((context)(activity)).getresources().getdrawable(r.drawable.marker_report_path_merge); bitmap b = bitmap.createbitmap(d.getintrinsicwidth(), d.getintrinsicheight(), bitmap.config.argb_8888); layerdrawable ld = (layerdrawable) ((context)(activity)).getresources().getdrawable(r.drawable.marker_report_path_merge); ld.setbounds(0, 0, d.getintrinsicwidth(), d.getintrinsicheight()); ld.draw(new canvas(b)); 

i getting error:

07-31 19:59:12.491: e/androidruntime(14341): fatal exception: main 07-31 19:59:12.491: e/androidruntime(14341): android.content.res.resources$notfoundexception: file res/drawable-hdpi/marker_report_path_merge.xml drawable resource id #0x7f020049 07-31 19:59:12.491: e/androidruntime(14341):    @ android.content.res.resources.loaddrawable(resources.java:1951) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.content.res.resources.getdrawable(resources.java:672) 07-31 19:59:12.491: e/androidruntime(14341):    @ com.recntrek.util.fragmentreportutils$2.onclick(fragmentreportutils.java:56) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.view.view.performclick(view.java:4211) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.view.view$performclick.run(view.java:17267) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.os.handler.handlecallback(handler.java:615) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.os.handler.dispatchmessage(handler.java:92) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.os.looper.loop(looper.java:137) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.app.activitythread.main(activitythread.java:4898) 07-31 19:59:12.491: e/androidruntime(14341):    @ java.lang.reflect.method.invokenative(native method) 07-31 19:59:12.491: e/androidruntime(14341):    @ java.lang.reflect.method.invoke(method.java:511) 07-31 19:59:12.491: e/androidruntime(14341):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1006) 07-31 19:59:12.491: e/androidruntime(14341):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:773) 07-31 19:59:12.491: e/androidruntime(14341):    @ dalvik.system.nativestart.main(native method) 07-31 19:59:12.491: e/androidruntime(14341): caused by: org.xmlpull.v1.xmlpullparserexception: binary xml file line #6: <bitmap> requires valid src attribute 07-31 19:59:12.491: e/androidruntime(14341):    @ android.graphics.drawable.bitmapdrawable.inflate(bitmapdrawable.java:448) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.graphics.drawable.drawable.createfromxmlinner(drawable.java:881) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.graphics.drawable.layerdrawable.inflate(layerdrawable.java:165) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.graphics.drawable.drawable.createfromxmlinner(drawable.java:881) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.graphics.drawable.drawable.createfromxml(drawable.java:818) 07-31 19:59:12.491: e/androidruntime(14341):    @ android.content.res.resources.loaddrawable(resources.java:1948) 07-31 19:59:12.491: e/androidruntime(14341):    ... 13 more 

but resources exist!

i tried cleaning build in eclipse, did not work.

can me?

thanks

edit:

here marker_report_path_merge.xml:

<?xml version="1.0" encoding="utf-8"?> <layer-list     xmlns:android="http://schemas.android.com/apk/res/android" >     <item android:drawable="@drawable/marker_report_blue" />     <item>       <bitmap android:src="@drawable/report_path_merge"               android:gravity="center_vertical|center_horizontal" />     </item> </layer-list> 

the reason why had error because didn't have real bitmap in <item> tag layer-list. can check code in bitmapdrawable class, inflate method

final bitmap bitmap = bitmapfactory.decoderesource(r, id); if (bitmap == null) {     throw new xmlpullparserexception(parser.getpositiondescription() +             ": <bitmap> requires valid src attribute"); } 

you posted exception.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -