【问题标题】:Jython: include custom java class [oanda]Jython:包含自定义 java 类 [oanda]
【发布时间】:2012-07-03 23:17:58
【问题描述】:
  >>> import sys
  >>> sys.path.append("/usr/local/oanda_fxtrade.jar") # add the jar to your path
   >>> 
  >>> import com.oanda.fxtrade.api.test.Example1 as main1
  >>> import com.oanda.fxtrade.api.test.Example2 as cancel
  main1("JPY",9,'-1')
  TypeError: main1("JPY",9,'-1'): expected 0 args; got 3

这似乎没有错误 - 但我真的需要一些参数

取消()
线程[Thread-0,5,main]

java类内部

  public final class Example1 extends Thread {
  private Example1() {
        super();
    }
 public static void main(String[] args) throws Exception {
FXClient fxclient  = API.createFXGame();

String username = "foo";
String password = "foo";
String sel=args[0];
String str1=args[1];
    String str2=args[2];

main1.main("JPY 9 -1")

TypeError: main(): 1st arg 不能被强制转换为 String[]

好吧,我想我进入了一个新的水平

【问题讨论】:

    标签: java jython


    【解决方案1】:

    之后

    import com.oanda.fxtrade.api.test.Example1 as main1
    

    main1 是类。在 java 中执行类将运行 main 但这并不意味着您可以将 args 传递给类。

    试试:

    main1.main(["JPY","9","-1"])
    

    编辑: 这里有两个不同的问题。

    对于后续的错误Could not initialize class com.oanda.fxtrade.api.API...看来你应该复习这个问题:Why does Jython refuse to find my Java package?

    调用 sys.path.append 添加 jar 不允许在加载时发生的包扫描器操作。您应该尝试手动导入所需的模块/类,或者在调用 jython 之前将 jar 添加到 CLASSPATH

    从这里我认为 jython 的答案已经存在,它变成了一个 com.oanda.fxtrade.api 问题,可能超出了 SO 范围。

    【讨论】:

    • main1() 尝试创建 Example1 类的实例,它不会运行 main()
    • 哎呀,这不是从命令行运行的。我应该测试它是否需要main1().main("args","go","here"),但我这里没有 oanda 罐子。
    • array=[ 0 for w in range(3)]; array=['JPY','9','-1']; main1.main(array)
    • TypeError: main(): 1st arg can't be coerced to String[] 好的,我想我进入了下一个级别
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-18
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    • 2017-04-24
    • 2010-12-31
    • 1970-01-01
    相关资源
    最近更新 更多