java - Runtime Error in Async Task -
java - Runtime Error in Async Task -
i'm trying build simple programme using asycn task on clicking button loads google home page in webview. have no errors showing in code when click button crashes next error:
an error occured while executing doinbackground() java.lang.runtimeexception:java.lang.throwable:a webview method called on thread 'asynctask #1'.all webview methods must called on same thread
this mainactivity.java
package com.example.asyncts2; import android.app.activity; import android.os.asynctask; import android.os.bundle; import android.view.view; import android.webkit.webview; import android.widget.button; import android.widget.toast; public class mainactivity extends activity { button button1; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button1 = (button) findviewbyid(r.id.button1); button1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { button1.setenabled(false); downloadwebpagetask task = new downloadwebpagetask(); task.execute(new string[] {"http://www.google.com/"}); } }); } private class downloadwebpagetask extends asynctask<string, void, string> { @override protected string doinbackground(string... urls) { webview webview = (webview) findviewbyid(r.id.webview1); webview.getsettings().setjavascriptenabled(true); webview.loadurl(urls[0]); homecoming "done"; } protected void onpostexecute(string result) { toast.maketext(mainactivity.this, "result", toast.length_short).show(); } }
this log cat errors
can point me going wrong? many thanks!
easy way handle to, whenever , wherever want access or modify webview, in uithread
runonuithread(new runnable() { @override public void run() { //shake webview here! } });
java android
Comments
Post a Comment