运行Java应用程序的第一个实例中出现Rserve()错误

运行Java应用程序的第一个实例中出现Rserve()错误,java,r,rserve,Java,R,Rserve,我正在用IntelliJ IDE编写一个Java应用程序。应用程序使用Rserve()连接到R并访问脚本。我有一个java脚本,它向shell发送启动Rserve()的命令。我现在面临的问题是第一次运行应用程序时,出现以下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.rosuda.REngine.REngineException.<init>(Lorg/rosuda/REngine/REngine;Lj

我正在用IntelliJ IDE编写一个
Java
应用程序。应用程序使用
Rserve()
连接到
R
并访问脚本。我有一个java脚本,它向shell发送启动
Rserve()
的命令。我现在面临的问题是第一次运行应用程序时,出现以下错误:

Exception in thread "main" java.lang.NoSuchMethodError: org.rosuda.REngine.REngineException.<init>(Lorg/rosuda/REngine/REngine;Ljava/lang/String;Ljava/lang/Throwable;)V
    at org.rosuda.REngine.Rserve.RserveException.<init>(RserveException.java:59)
    at org.rosuda.REngine.Rserve.RConnection.<init>(RConnection.java:90)
    at org.rosuda.REngine.Rserve.RConnection.<init>(RConnection.java:60)
    at org.rosuda.REngine.Rserve.RConnection.<init>(RConnection.java:44)
    at de.uni_jena.bioinformatik.RecalibrationGUI.Application.main(Application.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
下面是启动应用程序并调用
invoke()
方法的主java类:

public class Application {
    /**
     * Main method for the Swing application
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
            boolean value = InvokeRserve.invoke();
        RConnection check = new RConnection();
        if(check.isConnected())
        {
            // Run the GUI construction in the Event-Dispatching thread for thread-safety
            SwingUtilities.invokeLater(new Runnable() {

                /**
                 * run method which create a new GUIMain object
                 */
                @Override
                public void run() {new GUIMain("Java Application"); // Let the constructor do the job
                }
            });
       }
        else
        System.out.println("There was no R connection found.");
    }
}
另外,是否有方法停止现有的
Rserve()
连接(我读了不同的答案,建议使用
shutdown()
,但它对我不起作用)?每次,我都必须重新启动计算机以关闭现有连接,并启动新连接以测试上述代码

我还查看了位于的
startrservice.java
示例文件。但是当我在我的应用程序的主类中使用方法
startrservice.checkLocalRserve()
时,我得到了如上所示的相同的
Rserve()
错误。

您的
invoke()
方法在Rserve实际启动之前返回,因此您显然是在尝试过早连接。您可能需要添加
p.waitFor()。另请参见
startrservice
类,该类在从Java启动Rserve时更加健壮

PS:我建议使用for Rserve问题,它可以让您更快地回答问题。

您的
invoke()
方法在Rserve实际启动之前返回,因此您显然试图连接得太早了。您可能需要添加
p.waitFor()。另请参见
startrservice
类,该类在从Java启动Rserve时更加健壮


PS:我建议您使用for Rserve问题,它可以让您更快地回答问题。

我有一个解决方案,可以在不关闭计算机的情况下关闭Rserve连接。在打开Rconnection时尝试以下操作:

    RConnection rconn=null;
    try{
        rconn=new RConnection();
        //Your personal code here

    } catch(Exception exc){
        exc.printStackTrace(out);
    } finally{
        if (rconn!=null){
            rconn.close();
        }
    }
这样,当应用程序在中途停止时出现异常,它仍然运行finally部分并关闭连接。 希望这能及时帮助你


至于异常部分的详细信息,如果您可以在代码旁边显示行号,则可以回答,因为异常日志按行号引用代码。

我有一个解决方案,可以在不关闭计算机的情况下关闭Rserve连接。在打开Rconnection时尝试以下操作:

    RConnection rconn=null;
    try{
        rconn=new RConnection();
        //Your personal code here

    } catch(Exception exc){
        exc.printStackTrace(out);
    } finally{
        if (rconn!=null){
            rconn.close();
        }
    }
这样,当应用程序在中途停止时出现异常,它仍然运行finally部分并关闭连接。 希望这能及时帮助你

至于异常部分的详细信息,如果您可以在代码旁边显示行号,则可以回答,因为异常日志按行号引用代码