简体   繁体   中英

Rserve with java. Eval fail error 127

I got this error and i dont know what to do and couldnt find any other solution on this site. I run Rserve in the background on my computer and i connect to the local host. But i cant get the frame to popup.
Here is my code:

package rservedemo;

/**
 *
 * @author Carl
 */
import java.awt.*;

import java.awt.event.*;
import org.rosuda.REngine.*;
import org.rosuda.REngine.Rserve.*;

public class PlotDemo extends Canvas {


public static void main(String[] args) {

try 
{
    String device = "jpeg";
    RConnection c = new RConnection ((args.length>0)?args[0]:"127.0.0.1");
    if
            (c.parseAndEval("supressWarnings(require('Cairo',quietly=TRUE))").asInteger()>0) device="CarioJPEG";

    else
        System.out.println("(Consider installing Cairo package for better bitmap output)");

       REXP xp = c.parseAndEval("Try("+device+"('test.jpg,quality=90))");
       if (xp.inherits("Try error"))
       {
           System.err.println("Can't open "+device+" graphics device:\n" +xp.asString());

       REXP w = c.eval("If (exists('last.warning') && length(last.warning)>0)names(last.warning) [1] else 0");
       if (w.isString()) System.err.println(w.asString());
       return;
       }
       c.parseAndEval("data(iris); plot(iris$Sepal.Length, iris$Petal.Length); dev.off()");

       xp = c.parseAndEval("r=readBin('test.jpg','raw',1024*1024); unlink('test.jpg');r");

       Image img = Toolkit.getDefaultToolkit().createImage(xp.asBytes());
       Frame f = new Frame("Test image");
       f.add(new PlotDemo (img));

       f.addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e){System.exit(0);}

       });
       f.pack();
       f.setVisible(true);
       c.close();

}
catch (RserveException rse)
        {
            System.out.println(rse);
        }
    catch (REXPMismatchException mme)
    {
        System.out.println(mme);
        mme.printStackTrace();
    }
catch (Exception e)

{
    System.out.println("Seomthing went wrong, but it's not Rserve: " +e.getMessage());
    e.printStackTrace();
}

    }
    Image img;
    public PlotDemo(Image img)
    {
        this.img=img;
        MediaTracker mediaTracker = new MediaTracker(this);
        mediaTracker.addImage(img, 0);
        try
        {
            mediaTracker.waitForID(0);
        }
        catch (InterruptedException ie)
        {
            System.err.println(ie);
            System.exit(1);
        }
        setSize(img.getWidth(null), img.getHeight(null));      
    }
    public void paint (Graphics g)
    {
        g.drawImage(img, 0, 0, null);
    }
}

And here is the error, i have tried to change the line at 27 but couldnt do anything useful. When i run the

c.parseAndEval("data(iris); plot(iris$Sepal.Length, iris$Petal.Length); dev.off()"); 

in r and there it works. So that dosent seem to be the problem.

 Seomthing went wrong, but it's not Rserve: eval failed, request status: error code: 127
org.rosuda.REngine.REngineException: eval failed, request status: error code: 127
    at org.rosuda.REngine.Rserve.RConnection.parseAndEval(RConnection.java:454)
    at org.rosuda.REngine.REngine.parseAndEval(REngine.java:108)
    at rservedemo.PlotDemo.main(PlotDemo.java:27)

Thankful for help

Usually process exit code 127 means File not found . In you case problematic can be line:

REXP xp = c.parseAndEval("Try("+device+"('test.jpg,quality=90))");

because you could have mistake (typo) in line:

(c.parseAndEval("supressWarnings(require('Cairo',quietly=TRUE))").asInteger()>0) device="CarioJPEG";

Note: CarioJPEG instead of CairoJPEG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM