android - Error when retrieving image url? -
i keep getting error @
@override protected void doinbackground(void... arg0) { ((gallery) findviewbyid(r.id.gallery)) .setadapter(new imageadapter(this)); return null; } }
i syntax error @ (new imageadapter(this));
i dont know what. im guessing has context??
but here full code im using.
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); mygames = (button)findviewbyid(r.id.mygames); newrelease = (button)findviewbyid(r.id.newrelease); gamenews = (button)findviewbyid(r.id.news); gamenews.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent = new intent(mainmenu.this, gamenews.class); startactivity(i); } }); mytask mytask = new mytask(); mytask.execute(); } public void getimages() throws ioexception{ defaulthttpclient httpclient = new defaulthttpclient(); httpget httppost = new httpget("https://sites.google.com/site/theitrangers/images/webimages.txt"); httpresponse response; response = httpclient.execute(httppost); httpentity ht = response.getentity(); bufferedhttpentity buf = new bufferedhttpentity(ht); inputstream = buf.getcontent(); bufferedreader r = new bufferedreader(new inputstreamreader(is)); stringbuilder total = new stringbuilder(); string line; while ((line = r.readline()) != null) { total.append(line + "\n"); imageurl = total.tostring(); log.v("getimage2", "retreived image"); } } public void getimage2() throws ioexception{ defaulthttpclient httpclient = new defaulthttpclient(); httpget httppost = new httpget("https://sites.google.com/site/theitrangers/images/webimage2.txt"); httpresponse response; response = httpclient.execute(httppost); httpentity ht = response.getentity(); bufferedhttpentity buf = new bufferedhttpentity(ht); inputstream = buf.getcontent(); bufferedreader r = new bufferedreader(new inputstreamreader(is)); stringbuilder total = new stringbuilder(); string line; while ((line = r.readline()) != null) { total.append(line + "\n"); imageurl2 = total.tostring(); log.v("getimage2", "retreived image"); } } public class imageadapter extends baseadapter { /** parent context */ private context mycontext;public imageadapter() { // todo auto-generated constructor stub } /** url-strings remote images. */ private string[] myremoteimages = {imageurl,imageurl2}; /** simple constructor saving 'parent' context. */ public imageadapter(context c) { this.mycontext = c; } /** returns amount of images have defined. */ public int getcount() { return this.myremoteimages.length; } /* use array-positions unique ids */ public object getitem(int position) { return position; } public long getitemid(int position) { return position; } /** returns new imageview * displayed, depending on * position passed. */ public view getview(int position, view convertview, viewgroup parent) { imageview = new imageview(this.mycontext); try { /* open new url , inputstream load data it. */ url aurl = new url(myremoteimages[position]); urlconnection conn = aurl.openconnection(); conn.connect(); inputstream = conn.getinputstream(); /* buffered performance plus. */ bufferedinputstream bis = new bufferedinputstream(is); /* decode url-data bitmap. */ bitmap bm = bitmapfactory.decodestream(bis); bis.close(); is.close(); log.v(imageurl, "retrieving image"); /* apply bitmap imageview returned. */ i.setimagebitmap(bm); } catch (ioexception e) { log.e("debugtag", "remtoe image exception", e); } /* image should scaled width/height set. */ i.setscaletype(imageview.scaletype.fit_center); /* set width/height of imageview. */ i.setlayoutparams(new gallery.layoutparams(150, 150)); return i; } /** returns size (0.0f 1.0f) of views * depending on 'offset' center. */ public float getscale(boolean focused, int offset) { /* formula: 1 / (2 ^ offset) */ return math.max(0, 1.0f / (float)math.pow(2, math.abs(offset))); } } private class mytask extends asynctask<void, void, void>{ protected void onpreexecute(){ try { getimages(); log.v("mytask", "image 1 retreived"); getimage2(); log.v("mytask", "image 2 retreived"); } catch (ioexception e) { log.e("mainmenu retreive image", "image retreival failed"); e.printstacktrace(); } } @override protected void doinbackground(void... arg0) { ((gallery) findviewbyid(r.id.gallery)) .setadapter(new imageadapter(this)); return null; } } }
ah!! syntax error?? well, remove this, , try mainmenu.this.
Comments
Post a Comment