1
$\begingroup$

For my first attempt to call Mathematica from Java, I got the GraphicsApp sample program working, then defined a package with a function called "metric" and made sure that that package works when called from a notebook. Then I replaced this line from the GraphicsApp program

mathCanvas.setMathCommand(inputTextArea.getText())

with these lines, which replicate what I do in the notebook to call my package

ml.evaluateToInputForm("Needs[\"Riemann`Package1`\"];", 0);
ml.evaluateToInputForm("jacArray = ConstantArray[0,{4, 4}];", 0);
ml.evaluateToInputForm("jacArray = 
  {{r^2, 0, 0, 0}, {0, r^2 sin[x], 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};",0);
mathCanvas.setMathCommand("metric[jacArray]");

So when I press the Evaluate button, it runs my code instead of the expression from the input field. When I do this, it should display a 4x4 array. Instead it seems to display a 4 element array which is blinking really fast. It is hard to be sure but it seems to be cycling through the four 4 element sub-arrays displaying one at a time.

I dont know why it would act like this and have no idea how to go about debugging it. The package works fine from a notebook and it is a straightforward replacement of my 4 lines of code for the sample program's 1 line.

I would appreciated any suggestions.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.