Setting image in android twitter integration -
i have app integrate android & twitter. application permission given while loading profile , fetching data profile, app stops responding. logcat
shows nullpointerexception
@ onpostexecution. so, have put image loading part of code under comments. can make change in comments app works image loading alongside it? here code profile fragment
:
public class profilefragment extends fragment { textview prof_name; sharedpreferences pref; bitmap bitmap; imageview prof_img,tweet,signout,post_tweet; edittext tweet_text; progressdialog progress; dialog tdialog; string tweettext; @override public view oncreateview(layoutinflater inflater,viewgroup container, bundle args) { view view = inflater.inflate(r.layout.profile_fragment, container, false); prof_name = (textview)view.findviewbyid(r.id.prof_name); pref = getactivity().getpreferences(0); prof_img = (imageview)view.findviewbyid(r.id.prof_image); tweet = (imageview)view.findviewbyid(r.id.tweet); signout = (imageview)view.findviewbyid(r.id.signout); signout.setonclicklistener(new signout()); tweet.setonclicklistener(new tweet()); new loadprofile().execute(); return view; } private class signout implements onclicklistener { @override public void onclick(view arg0) { // todo auto-generated method stub sharedpreferences.editor edit = pref.edit(); edit.putstring("access_token", ""); edit.putstring("access_token_secret", ""); edit.commit(); fragment login = new loginfragment(); fragmenttransaction ft = getactivity().getfragmentmanager().begintransaction(); ft.replace(r.id.content_frame, login); ft.settransition(fragmenttransaction.transit_fragment_fade); ft.addtobackstack(null); ft.commit(); } } private class tweet implements onclicklistener { @override public void onclick(view v) { // todo auto-generated method stub tdialog = new dialog(getactivity()); tdialog.requestwindowfeature(window.feature_no_title); tdialog.setcontentview(r.layout.tweet_dialog); tweet_text = (edittext)tdialog.findviewbyid(r.id.tweet_text); post_tweet = (imageview)tdialog.findviewbyid(r.id.post_tweet); post_tweet.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub new posttweet().execute(); } }); tdialog.show(); }} private class posttweet extends asynctask<string, string, string> { @override protected void onpreexecute() { super.onpreexecute(); progress = new progressdialog(getactivity()); progress.setmessage("posting tweet ..."); progress.setprogressstyle(progressdialog.style_spinner); progress.setindeterminate(true); tweettext = tweet_text.gettext().tostring(); progress.show(); } protected string doinbackground(string... args) { configurationbuilder builder = new configurationbuilder(); builder.setoauthconsumerkey(pref.getstring("consumer_key", "")); builder.setoauthconsumersecret(pref.getstring("consumer_secret", "")); accesstoken accesstoken = new accesstoken(pref.getstring("access_token", ""), pref.getstring("access_token_secret", "")); twitter twitter = new twitterfactory(builder.build()).getinstance(accesstoken); try { twitter4j.status response = twitter.updatestatus(tweettext +" @learn2crack "); return response.tostring(); } catch (twitterexception e) { // todo auto-generated catch block e.printstacktrace(); } return null; } protected void onpostexecute(string res) { if(res != null){ progress.dismiss(); toast.maketext(getactivity(), "tweet sucessfully posted", toast.length_short).show(); tdialog.dismiss(); }else{ progress.dismiss(); toast.maketext(getactivity(), "error while tweeting !", toast.length_short).show(); tdialog.dismiss(); } } } private class loadprofile extends asynctask<string, string, bitmap> { @override protected void onpreexecute() { super.onpreexecute(); progress = new progressdialog(getactivity()); progress.setmessage("loading profile ..."); progress.setprogressstyle(progressdialog.style_spinner); progress.setindeterminate(true); progress.show(); } protected bitmap doinbackground(string... args) { try { bitmap = bitmapfactory.decodestream((inputstream)new url(pref.getstring("image_url", "")).getcontent()); } catch (exception e) { e.printstacktrace(); } return bitmap; } protected void onpostexecute(bitmap image) { /* bitmap image_circle = bitmap.createbitmap(bitmap.getwidth(), bitmap.getheight(), bitmap.config.argb_8888); bitmapshader shader = new bitmapshader (bitmap, tilemode.clamp, tilemode.clamp); paint paint = new paint(); paint.setshader(shader); canvas c = new canvas(image_circle); c.drawcircle(image.getwidth()/2, image.getheight()/2, image.getwidth()/2, paint); prof_img.setimagebitmap(image_circle);*/ prof_name.settext("welcome " +pref.getstring("name", "")); progress.hide(); } }
}
Comments
Post a Comment