Throwing exception when i open android webview in qt 5.2 using android extras
-
wrote on 27 Feb 2014, 10:47 last edited by
Hi,
I am getting the following Throwable Exception when I try to display android Webview using setContentView() of android in Qt Application.W/webview_proxy( 9549): java.lang.Throwable: Warning: A WebView method was called on thread 'Thread-845'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
W/webview_proxy( 9549): at android.webkit.WebView.checkThread(WebView.java:1895)
W/webview_proxy( 9549): at android.webkit.WebView.ensureProviderCreated(WebView.java:1878)
W/webview_proxy( 9549): at android.webkit.WebView.setOverScrollMode(WebView.java:1935)
W/webview_proxy( 9549): at android.view.View.<init>(View.java:3346)
W/webview_proxy( 9549): at android.view.View.<init>(View.java:3422)
W/webview_proxy( 9549): at android.view.ViewGroup.<init>(ViewGroup.java:432)
W/webview_proxy( 9549): at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:52)
W/webview_proxy( 9549): at android.webkit.WebView.<init>(WebView.java:505)
W/webview_proxy( 9549): at android.webkit.WebView.<init>(WebView.java:482)
W/webview_proxy( 9549): at android.webkit.WebView.<init>(WebWhy this is happening, Please provide the solution.
Thanks
Kranthi Talluri -
wrote on 27 Feb 2014, 11:37 last edited by
The error message indicates also the solution:
"All WebView methods must be called on the UI thread."
So, you must execute the method on the UI thread. For doing so, the Android API provides the runOnUIThread method:
http://developer.android.com/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable) -
wrote on 27 Feb 2014, 13:26 last edited by
I written the code as follows even then it is throwing same Exception:
public void invokeview(){
final Activity activity=this; webView = new WebView(this); new Thread() { public void run() { try { activity.runOnUiThread(new Runnable() { @Override public void run() { webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("http://www.google.com"); setContentView(webView); } }); } catch (Exception e) { e.printStackTrace(); } } }.start(); }
1/3