0

I have a webview which has HTML with a link calling Android.closeRegForm() in WebAppInterface i have a method

@JavascriptInterface
    public void closeRegForm() {
        ((MainActivity)mContext).closeRegForm();
    }

which must call method closeRegForm on MainActivity, but I am getting this error.

09-10 12:54:50.134: E/Web Console(1171): Uncaught Error: Error calling method on NPObject. at http://example.com/aaa.php:1

when I change this method to

@JavascriptInterface
    public void closeRegForm() {
        Toast.makeText(mContext, "blabla", Toast.LENGTH_SHORT).show();
    }

it shows "blabla" toast. Why I cannot call method on mainactivity?

2
  • "Uncaught Error" suggests there's an exception of some sort. Surround with try/catch and log it. Commented Sep 10, 2013 at 13:06
  • thanks, I got this error, 09-10 13:11:03.526: D/qwe(1242): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. I know what to do whit it. Commented Sep 10, 2013 at 13:11

1 Answer 1

3

You have to add the function of different name in MainActivity

public void closeRegForm1() {
    //Anything
}

Note: This should be public

And then call as

@JavascriptInterface
public void closeRegForm() {
    ((MainActivity)mContext).closeRegForm1();
}
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.