Android Uncaught Error Error Calling Method On Npobject
Contents |
here for a quick overview of the site Help Center Detailed answers to any error calling method on npobject android webview questions you might have Meta Discuss the workings and policies error calling method on npobject applet of this site About Us Learn more about Stack Overflow the company Business Learn more
Error Calling Method On Npobject Javascript
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack
Error Calling Method On Npobject Firefox
Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Sometimes throws Uncaught Error: Error calling method on NPObject on Android up vote 20 down vote favorite 10 I am having problems with the Webview in Android and it's error calling method on npobject safari JavascriptInterfaces. I am passing a string to the JavascriptInterface. When debugging it, I receive the correct string within my Android application. The problem: Sometimes I get an Uncaught Error: Error calling method on NPObject. Does anybody know why? The Interface in Java: public class JSInterfaceGame extends JSInterface { @JavascriptInterface public void setShareText(String share){ shareText = share; if(mJSInterfaceListener != null) mJSInterfaceListener.onParametersChanged(SHARE_TEXT); } The initialization in the onCreateView-Method within the Fragment: online = (WebView) rootView.findViewById(R.id.online); online.setWebViewClient(new WISWebviewClient() { @Override public void onStatusChanged(final WebView view, int progress, long duration) { //unrelated } }); WebSettings ws = online.getSettings(); ws.setJavaScriptEnabled(true); ws.setUserAgentString(USER_AGENT); ws.setCacheMode(WebSettings.LOAD_DEFAULT); ws.setRenderPriority(WebSettings.RenderPriority.HIGH); SharedPreferences settings = getActivity().getSharedPreferences(GameActivity.PREFERENCES, Context.MODE_PRIVATE); mJSInterface = new JSInterfaceGame(); mJSInterface.setJSInterfaceListener(this); // Defined elsewhere in this class. mJSInterface.setPlayerName(settings.getString(GameActivity.PREFS_PlAYERNAME, null)); online.addJavascriptInterface(mJSInterface, "JSInterface"); online.loadUrl("http://myurl.something"); Call in Javascript: function makeShareText() { var text = "Some text"; console.log(typeof text); // Always a string. JSInterface.setShareText(text); } android android-webview android-jsinterface share|improve this question edited Mar 31 at 9:10 asked May 26
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site
Error Calling Method On Npobject Android Phonegap
About Us Learn more about Stack Overflow the company Business Learn more about error calling method on npobject solution hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss error error calling method on npobject firefox Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error calling method http://stackoverflow.com/questions/16758397/sometimes-throws-uncaught-error-error-calling-method-on-npobject-on-android on NPObject! in Android 2.2 up vote 11 down vote favorite 1 I'm using addJavascriptInterface within my Android application to allow JavaScript to invoke functions I've created in my native Java application. This worked well in Android 2.1, however in Android 2.2 I receive the error message "Error calling method on NPObject!" When I instrument the method call the internals of the native method are http://stackoverflow.com/questions/3344256/error-calling-method-on-npobject-in-android-2-2 getting called, however the exception is being throw in JavaScript. android android-webview share|improve this question asked Jul 27 '10 at 13:44 Kevin 4,121113647 I'm having the same issue. Did you managed to solve it? –grzaks Jul 25 '11 at 9:37 add a comment| 6 Answers 6 active oldest votes up vote 11 down vote I was getting this exact error: Uncaught Error: Error calling method on NPObject! Turns out I was attempting to invoke a JavascriptInterface function from a webview like so: AndroidJS.populateField(field); and on the Java side, the function didn't accept a parameter: public void populateField() {} Simply allowing the Java function to accept a parameter solved this error for me. E.g., public void populateField(String field) {} This may not be, and probably is not, the only reason this error could be thrown. This is simply how I resolved my specific scenario. Hope this helps! :) share|improve this answer answered May 18 '12 at 16:30 muffs 615814 add a comment| up vote 5 down vote In my experience this problem is caused by Javascript interfaces bringing back objects that Javascript doesn't automatically identify. In Android this is caused by wrappe
side, the function didn't accept a parameter: public void populateField() {} Simply allowing the Java function to accept a parameter solved this error for me. public void populateField(String field) {} This may not be, and probably is not, the only reason https://recalll.co/app/?q=Error%20calling%20method%20on%20NPObject!%20in%20Android%202.2 this error could be thrown. This is simply how I resolved my specific scenario. Hope this helps! :) Error calling method on NPObject! in Android 2.2 - Stack Overflow View More at http://stackoverflow.com/questions/3344256/error-calling-method-o... Another reason can be https://github.com/phonegap-build/PushPlugin/issues/92 a RuntimeException on a WebViewCoreThread. Any exception occurred after receiving @JavascriptInterface call will be logged as NPObject error if still running on a WebView thread. Overall insufficient trace message with little clue about the problem. Correct your error calling issue with handling javascript interface call on a suitable thread. @JavascriptInterface public void jsCall() { new Thread(new Runnable() { @Override public void run() { Log.v(TAG, "Prepared NullPointerException on " + Thread.currentThread()); String s = null; s.length(); // This will throw NullPointerException } }).start(); } Take this as an addition to @Nico.S's answer. Sometimes throws Uncaught Error: Error calling method on NPObject on A... View More at http://stackoverflow.com/questions/16758397/sometimes-throws-unca... Here's a twist I found on this error calling method problem that could be useful for some of the folks running into this problem (and it likely explains intermittent failures that seem to defy explanation)... If any exceptions are thrown (and not caught) in the return handler code prior to allowing the javascript interface callback to return clean, it will propagate back as a failed call and you will also get this error - and it would have nothing to do with missing functions or parameters. The easiest way to find this case (whether or not you use this in your final implementation) is to push whatever handler code you have back onto the UI thread (the callback will not be on the UI thread) - this will allow the callback to return clean and any subsequent exceptions that occur will propagate properly up until you catch them or until the app crashes. Either way you will see exactly what is really happening. Otherwise the uncaught exception passes back to javascript where it will not be handled or reported in any way (unless you specifically built error trapping code into the JS you were executing). ok, sound great but how exactly can we do that? how can we push handler code on the ui thread? Error calling method on NPObject! in Android 2.2 - Stack Overflow View More at http://stackoverflow.com/questions/3344256/error-calling-metho