Wednesday, 15 September 2010

android - Network error when loading an Image from URL -



android - Network error when loading an Image from URL -

this question has reply here:

how prepare android.os.networkonmainthreadexception? 33 answers

i loading image url converting bitmap , adding marker in maps. have 2 markers 1 profile , other friends profile.

when load image next error , image doesn't loaded. no forcefulness close too.

android.os.networkonmainthreadexception

i not sure kind of error this.

here code trying: same below code works fine profile pic. comes when seek load friends list.

i calling below within loop.

for (int = 0; < friendslist.size(); i++) { username = friendslist.get(i).getname(); lati = friendslist.get(i).getlati(); longi = friendslist.get(i).getlongi(); photourl = friendslist.get(i).getimage(); loadmyfriendslocation(double.parsedouble(lati), double.parsedouble(longi), username, photourl, 15); }

and loadmyfriendsloaction method has following:

view marker = getactivity().getlayoutinflater().inflate(r.layout.activity_myfriendslocationmap, null); imageview friendimageview = (imageview) marker.findviewbyid(r.id.badge); seek { inputstream in = new java.net.url(urlfriends).openstream(); bitmap micon11 = bitmapfactory.decodestream(in); friendimageview.setimagebitmap(micon11); } grab (exception e) { log.e("error", "message"+e); e.printstacktrace(); } //to convert view bitmap marker.measure(measurespec.makemeasurespec(0, measurespec.unspecified), measurespec.makemeasurespec(0, measurespec.unspecified)); marker.layout(0, 0, marker.getmeasuredwidth(),marker.getmeasuredheight()); final bitmap icon = bitmap.createbitmap(marker.getmeasuredwidth(), marker.getmeasuredheight(), bitmap.config.argb_8888); canvas canvas = new canvas(icon); marker.draw(canvas); markeroptions markeroptionsforfriends = new markeroptions().position(position).icon(bitmapdescriptorfactory.frombitmap(icon)).title(uname).anchor(0.5f, 1f); markerforfriends = googlemap.addmarker(markeroptionsforfriends);

i totally blank here don't know go wrong because profile image has same code comes friends pics don't come up...

can help me prepare issue?

thanks!

this exception thrown when application attempts perform networking operation on main thread. have utilize below :-

thread

thread thread = new thread(new runnable(){ @override public void run() { seek { //your code goes here } grab (exception e) { e.printstacktrace(); } } }); thread.start();

asynctask

private class downloadwebpagetask extends asynctask<string, void, string> { @override protected string doinbackground(string... urls) { //your code goes here homecoming response; } @override protected void onpostexecute(string result) { textview.settext(result); }

}

strictmode.threadpolicy

strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy);

android google-maps google-maps-markers google-maps-api-2

No comments:

Post a Comment