用于更改屏幕方向的phonegap插件出错

时间:2012-07-23 06:36:06

标签: javascript android cordova

我收到此错误。

  

未捕获的TypeError:对象#在文件中没有方法'exec':///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)

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

我在调用exec时遇到此错误。在

之前的任何地方运作
  

onDeviceReady()

事件已经解雇。