“./Main.java:29:错误:类JLineConsole中的构造函数JLineConsole无法应用于给定类型;”尝试从Python文件生成JAR时
../Main.java:29: error: constructor JLineConsole in class JLineConsole cannot be applied to given types;
return new JLineConsole();
^
required: String
found: no arguments
reason: actual and formal argument lists differ in length
1 error
就是我的错误。我遵循here中的说明,但在一个用户将Lib添加到Jython/Lib后,我反复被困在该部分:
$ javac ../Main.java -d .
当我尝试执行这个命令时,上面提到的错误被抛出。以下是相关的Java:
import java.io.FileInputStream;
import java.lang.System;
import java.util.Properties;
import org.python.core.Py;
import org.python.core.PyException;
import org.python.core.PyFile;
import org.python.core.PySystemState;
import org.python.util.JLineConsole;
import org.python.util.InteractiveConsole;
import org.python.util.InteractiveInterpreter;
public class Main {
private static InteractiveConsole newInterpreter(boolean interactiveStdin) {
if (!interactiveStdin) {
return new InteractiveConsole();
}
String interpClass = PySystemState.registry.getProperty(
"python.console", "");
if (interpClass.length() > 0) {
try {
return (InteractiveConsole)Class.forName(
interpClass).newInstance();
} catch (Throwable t) {
// fall through
}
}
return new JLineConsole();
}
public static void main(String[] args) throws PyException {
PySystemState.initialize(
PySystemState.getBaseProperties(),
new Properties(), args);
PySystemState systemState = Py.getSystemState();
// Decide if stdin is interactive
boolean interactive = ((PyFile)Py.defaultSystemState.stdin).isatty();
if (!interactive) {
systemState.ps1 = systemState.ps2 = Py.EmptyString;
}
// Now create an interpreter
InteractiveConsole interp = newInterpreter(interactive);
systemState.__setattr__("_jy_interpreter", Py.java2py(interp));
interp.exec("try:\n import entrypoint\n entrypoint.main()\nexcept SystemExit: pass");
}
}
我对Java不是特别精通,但据我所知,我不认为这有什么不对
我已经尝试了很多次,并查找了与我收到的错误消息相关的StackOverflow问题,但它们似乎都不适用
我还尝试使用命令$ java ../Main.java
运行Java文件本身。这引发了另一个错误:
Error: Could not find or load main class ...Main.java
我在这里查阅过,但这些错误似乎都不适用于我的情况;然而,有人建议我使用java -Xdiag
来获取更有用的错误消息。我做到了,这产生了:
java.lang.ClassNotFoundException: ...Main.java
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
据我所知,这与非详细的错误消息是一样的,并没有给我一条明确的前进道路。这里有人有什么想法吗
共 (0) 个答案