1

我收到此错误。

Uncaught TypeError: Object # has no method 'exec' at file:///android_asset/www/JS/pg-plugin-screen-orientation.js:4

var screenOrientation = function() {}

screenOrientation.prototype.set  = function(str, success, fail) {

 PhoneGap.exec(success, fail, "ScreenOrientation", "set", [str]); // GETTING ERROR IN THIS LINE

};

navigator.screenOrientation = new screenOrientation();

我已按照本文档中给出的步骤进行操作。 https://github.com/champierre/pg-plugin-screen-orientation


现在它工作正常。但是当这条线被执行时应用程序崩溃了

activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

07-24 18:01:19.200: E/AndroidRuntime(12001): FATAL EXCEPTION: main
07-24 18:01:19.200: E/AndroidRuntime(12001): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4054e820 is not valid; is your activity running?
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.view.ViewRoot.setView(ViewRoot.java:527)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.view.Window$LocalWindowManager.addView(Window.java:424)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.app.Dialog.show(Dialog.java:241)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at org.apache.cordova.Notification$1.run(Notification.java:205)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.app.Activity.runOnUiThread(Activity.java:3717)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at org.apache.cordova.Notification.alert(Notification.java:208)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at org.apache.cordova.Notification.execute(Notification.java:70)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at org.apache.cordova.api.PluginManager.exec(PluginManager.java:212)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at org.apache.cordova.CordovaChromeClient.onJsPrompt(CordovaChromeClient.java:185)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:566)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.os.Looper.loop(Looper.java:123)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.app.ActivityThread.main(ActivityThread.java:3683)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at java.lang.reflect.Method.invokeNative(Native Method)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at java.lang.reflect.Method.invoke(Method.java:507)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-24 18:01:19.200: E/AndroidRuntime(12001):    at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

1

您使用的是哪个版本的 PhoneGap/Cordova?该PhoneGap对象已重命名为cordova最新版本。因此,您可能需要更新 JS 文件以调用cordova.exec而不是PhoneGap.exec.

于 2012-07-24T12:56:10.240 回答
1

当我调用 exec 时出现此错误。在之前的任何地方起作用

onDeviceReady()

事件已触发。

于 2012-08-30T05:42:44.367 回答