2

I have a javascript interface class to receive some values from javascript. I toasted that value from interface class but I can not settext that value to a TextVie. What will be the problem??

 class JavaScriptInterfaceForCount {
    Context mContext;

    JavaScriptInterfaceForCount(Context c) {
        mContext = c;
    }
    public void receiveValueFromJs(String scrollwidth, String columwidth) {
            mPagenumberTextView.setText(scrollwidth+"");
      }
 }

Logcat result

06-08 16:20:37.003: E/AndroidRuntime(1198):                android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created     a view hierarchy can touch its views.
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.ViewRoot.requestLayout(ViewRoot.java:594)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.View.requestLayout(View.java:8125)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.View.requestLayout(View.java:8125)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.View.requestLayout(View.java:8125)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.View.requestLayout(View.java:8125)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:254)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.View.requestLayout(View.java:8125)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.widget.TextView.checkForRelayout(TextView.java:5378)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.widget.TextView.setText(TextView.java:2688)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.widget.TextView.setText(TextView.java:2556)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.widget.TextView.setText(TextView.java:2531)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at com.epub.reader.TestWebActivity$JavaScriptInterfaceForCount.receiveValueFromJs(TestWebActivity.java:326)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:245)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1562)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.WebViewCore.access$1400(WebViewCore.java:52)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:948)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.os.Looper.loop(Looper.java:123)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:621)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at java.lang.Thread.run(Thread.java:1096)

1 Answer 1

6
runOnUiThread(new Runnable() {
     public void run() {
         mPagenumberTextView.setText(scrollwidth+"");
    }
});

You have to edit the UI in the main thread

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.