Re: Sending Objects from Java - Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg91048] Re: Sending Objects from Java - Mathematica
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Mon, 4 Aug 2008 03:26:10 -0400 (EDT)
- References: <g670pq$s5q$1@smc.vnet.net>
Jochen Adamek wrote: > Dear Mathematica-experts, > > i have written a Java-code, where i want to send some objects to > Mathematica. To call a function(written in Mathematica) with four > parameters under Java, i need to send objects to Mathematica. > > This is my Java-code: > > > public void sendListOfEdgesToMathematica(List<String> edg) throws > MathLinkException { > try { > > ml = MathLinkFactory.createKernelLink(argv); > } catch (MathLinkException e) { > System.out.println("Fatal error opening link: " + > e.getMessage()); > return; > } > > try { > ml.enableObjectReferences(); > ml.discardAnswer(); > ml.evaluate("<<C:\\Java\\AGG_Engine_Mathematica\\examples.nb"); > ml.discardAnswer(); > ml.putFunction("EvaluatePacket", 1); > ml.putFunction("doGetEdges", 1); > ml.put(edg); > ml.endPacket();.............. > > edg( a list) contains the element "e11" and i have written a Function > under Mathematica for receiving the object from Java: > > > doGetEdges[edg_] := > JavaBlock[Module[{outStream}, outStream = edg@getOutputStream[]; > outStream@print["Edges"]; > edgesG6 = edg > ] > ] > > The problem is, Mathematica does not receive the correct value("e11"). > I tried to test my implementation with a PacketListener, but without > success. After sending four objects to Mathematica, i want to call the > Mathematica-function under Java: > > "objectGraph[edgesG6, verticesG6, sourcesG6, targetsG6]" > > Any help would be fantastic. > > Best regards J.Adamek > Unless you really need to work at such a low level, it is much easier to call StdLink.getLink().evaluateToInputForm(str,0); Where str is a string representation of the Mathematica function call you want to make. As for your code, I would need to be able to debug it to be sure, but I think the problem is that you need to explicitly generate the list using: ml.putFunction("List", 1); (followed by the 1 element of your list) David Bailey http://www.dbaileyconsultancy.co.uk