java - How to make a toast in an onfailure method -
so use okhttp in separate service fetch data twitter api. have been trying alert user tweets cannot loaded without internet connection. when try this, application crashes.the error : java.lang.runtimeexception: can't create handler inside thread has not called looper.prepare(). here's code
private void gettweets(final string topic) { final twitterservice twitterservice = new twitterservice(); twitterservice.findtweets(topic, new callback() { @override public void onfailure(request request, ioexception e) { e.printstacktrace(); log.e("traffic activity", "failed make api call"); toast.maketext(getapplicationcontext(), "bigger fail", toast.length_long).show(); }
probably calling toast.maketext wrong thread. needs called ui thread. try instead
activity.runonuithread(new runnable() { public void run() { toast.maketext(activity, msg, toast.length_short).show(); } });
more informations here can't create handler inside thread has not called looper.prepare()
Comments
Post a Comment