Throwing exception when i open android webview in qt 5.2 using android extras



  • 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>(Web

    Why this is happening, Please provide the solution.

    Thanks
    Kranthi Talluri



  • 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)



  • 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();
    }

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.