2012-03-10 46 views
1

我想单独使用IronPython(使用Android 4手机),以便我可以在我的项目中执行python脚本。我将代码从这里的示例中删除:Instantiating a python class in C#与monodroid使用IronPython - NotImplementedError

我已经在Android平台目录中使用了dll(使用IronPython-2.7.2rc1),并在项目目录中有一个python脚本(现在是一个测试脚本所谓计算器从例如链接)

以下是我的C#代码:

using System; 
using Android.App; 
using Android.Content; 
using Android.Runtime; 
using Android.Views; 
using Android.Widget; 
using Android.OS; 
using IronPython; 
using IronPython.Hosting; 
using Microsoft.Scripting; 
using Microsoft.Scripting.Hosting; 
namespace PythonTest 
{ 
    [Activity (Label = "PythonTest", MainLauncher = true)] 
    public class Activity1 : Activity 
    { 
     int count = 1; 
     protected override void OnCreate (Bundle bundle) 
     { 
      base.OnCreate (bundle); 

      // Set our view from the "main" layout resource 
      SetContentView (Resource.Layout.Main); 

      ScriptEngine engine = Python.CreateEngine(); 
      ScriptSource source = engine.CreateScriptSourceFromFile("Calculator.py"); 
      ScriptScope scope = engine.CreateScope(); 
      ObjectOperations op = engine.Operations; 
      source.Execute(scope); // class object created 
      object klaz = scope.GetVariable("Calculator"); // get the class object 
      object instance = op.Invoke(klaz); // create the instance 
      object method = op.GetMember(instance, "add"); // get a method 
      int result = (int)op.Invoke(method, 4, 5); // call method and get result (9) 


      var aLabel = new TextView (this); 
      //aLabel.Text = result.ToString(); 

      // Get our button from the layout resource, 
      // and attach an event to it 
      Button button = FindViewById<Button> (Resource.Id.myButton); 

      button.Click += delegate { 
       button.Text = string.Format ("{0} clicks!", count++); }; 
     } 
    } 
} 

它建立没有任何错误。当我尝试我的手机上运行此,我得到这些错误和程序崩溃(电话回到主屏幕)

I/monodroid-gc(2110): environment supports jni NewWeakGlobalRef 

I/MonoDroid(2110): UNHANDLED EXCEPTION: System.NotImplementedException: The requested feature is not implemented. 

I/MonoDroid(2110): at Microsoft.Scripting.PlatformAdaptationLayer.OpenInputFileStream (string) <0x0001c> 

I/MonoDroid(2110): at Microsoft.Scripting.FileStreamContentProvider/PALHolder.GetStream (string) <0x0002b> 

I/MonoDroid(2110): at Microsoft.Scripting.FileStreamContentProvider.GetStream() <0x00023> 

I/MonoDroid(2110): at Microsoft.Scripting.Runtime.LanguageBoundTextContentProvider.GetReader() <0x00027> 

I/MonoDroid(2110): at Microsoft.Scripting.SourceUnit.GetReader() <0x00023> 

I/MonoDroid(2110): at IronPython.Compiler.Parser.CreateParserWorker (Microsoft.Scripting.Runtime.CompilerContext,IronPython.PythonOptions,bool) <0x000bf> 

I/MonoDroid(2110): at IronPython.Compiler.Parser.CreateParser (Microsoft.Scripting.Runtime.CompilerContext,IronPython.PythonOptions) <0x0001f> 

I/MonoDroid(2110): at IronPython.Runtime.PythonContext.ParseAndBindAst (Microsoft.Scripting.Runtime.CompilerContext) <0x0005f> 

I/MonoDroid(2110): at IronPython.Runtime.PythonContext.CompilePythonCode (Microsoft.Scripting.SourceUnit,Microsoft.Scripting.CompilerOptions,Microsoft.Scripting.ErrorSink) <0x0008f> 

I/MonoDroid(2110): at IronPython.Runtime.PythonContext.CompileSourceCode (Microsoft.Scripting.SourceUnit,Microsoft.Scripting.CompilerOptions,Microsoft.Scripting.ErrorSink) <0x0002b> 

I/MonoDroid(2110): at Microsoft.Scripting.SourceUnit.Compile (Microsoft.Scripting.CompilerOptions,Microsoft.Scripting.ErrorSink) <0x0005b> 

I/MonoDroid(2110): at Microsoft.Scripting.SourceUnit.Execute (Microsoft.Scripting.Runtime.Scope,Microsoft.Scripting.ErrorSink) <0x00057> 

I/MonoDroid(2110): at Microsoft.Scripting.SourceUnit.Execute (Microsoft.Scripting.Runtime.Scope) <0x00027> 

I/MonoDroid(2110): at Microsoft.Scripting.Hosting.ScriptSource.Execute (Microsoft.Scripting.Hosting.ScriptScope) <0x00043> 

I/MonoDroid(2110): at PythonTest.Activity1.OnCreate (Android.OS.Bundle) <0x000c3> 

I/MonoDroid(2110): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x00057> 

I/MonoDroid(2110): at (wrapper dynamic-method) object.5a9608db-a03f-4bd2-831d-6cb21e250354 (intptr,intptr,intptr) <0x00033> 

E/mono (2110): 

E/mono (2110): Unhandled Exception: System.NotImplementedException: The requested feature is not implemented. 

E/mono (2110): at Microsoft.Scripting.PlatformAdaptationLayer.OpenInputFileStream (System.String path) [0x00000] in <filename unknown>:0 

E/mono (2110): at Microsoft.Scripting.FileStreamContentProvider+PALHolder.GetStream (System.String path) [0x00000] in <filename unknown>:0 

E/mono (2110): at Microsoft.Scripting.FileStreamContentProvider.GetStream() [0x00000] in <filename unknown>:0 

E/mono (2110): at Microsoft.Scripting.Runtime.LanguageBoundTextContentProvider.GetReader() [0x00000] in <filename unknown>:0 

E/mono (2110): at Microsoft.Scripting.SourceUnit.GetReader() [0x00000] in <filename unknown>:0 

E/mono (2110): at IronPython.Compiler.Parser.CreateParserWorker (Microsoft.Scripting.Runtime.CompilerContext context, IronPython.PythonOptions options, Boolean verbatim) [0x00000] in <filename unknown>:0 

E/mono (2110): at IronPython.Compiler.Parser.CreateParser (Microsoft.Scripting.Runtime.CompilerContext context, IronPython.PythonOptions options) [0x00000] in <filename unknown>:0 

E/mono (2110): at IronPython.Ru 

有谁知道如何解决这一问题?谢谢。

回答

0

看起来像一个直线的错误(PAL的Android是不完整的),它看起来像你已经打开一个问题(谢谢!)。

IronPython的支持非常早,所以测试它和报告问题的人越多越好。