I want to connect an android application with Mathematica, in order to make some computations and then return the results to the user. I have downloaded Mathmatika and run the Examples from JLink library in commandline. Everything works fine. The problem is when I enter the code in Android Studio.

The code I am using is this:

import com.wolfram.jlink.*;
public class vathmou extends ActionBarActivity {

Button lbtn;
Button clear_btn;

EditText a1;
EditText b1;

protected void onCreate(Bundle savedInstanceState) {
    KernelLink ml = null;
    String argv ="-linkmode launch -linkname \"C:/Program Files/Wolfram Research/Mathematica/10.4/MathKernel.exe\"";
    System.out.println("OK1 ");

    try {
        ml = MathLinkFactory.createKernelLink(argv);
        System.out.println("OK ");
        Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_SHORT).show();

    } catch (MathLinkException  e) {
        Toast.makeText(getApplicationContext(), "Fatal error opening link: " + e.getMessage(), Toast.LENGTH_SHORT).show();

        System.out.println("Fatal error opening link: " + e.getMessage());

    try {
        // Get rid of the initial InputNamePacket the kernel will send
        // when it is launched.



        int result = ml.getInteger();
        System.out.println("2 + 2 = " + result);
        Toast.makeText(getApplicationContext(), "2+2 " + result, Toast.LENGTH_SHORT).show();
        // Here's how to send the same input, but not as a string:
        ml.putFunction("EvaluatePacket", 1);
        ml.putFunction("Plus", 2);
        result = ml.getInteger();
        System.out.println("3 + 3 = " + result);

        String strResult = ml.evaluateToOutputForm("4+4", 0);
        System.out.println("4 + 4 = " + strResult);

    } catch (MathLinkException e) {
        System.out.println("MathLinkException occurred: " + e.getMessage());
    } finally {

The error I get is the one below:

Could not find class 'java.awt.Window', referenced from method com.wolfram.jlink.KernelLinkImpl.addTitleChangeListener
Unable to resolve superclass of Lcom/wolfram/jlink/MathJFrame; (2233)
Link of class 'Lcom/wolfram/jlink/MathJFrame;' failed
Unable to resolve superclass of Lcom/wolfram/jlink/ui/ConsoleWindow; (1894)
Link of class 'Lcom/wolfram/jlink/ui/ConsoleWindow;' failed
Could not find method com.wolfram.jlink.ui.ConsoleWindow.getInstance, referenced from method com.wolfram.jlink.KernelLinkImpl.getConsole

Have I done something wrong? Could anyone please help me, please?

  • $\begingroup$ Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Oct 4 '16 at 16:43
  • 1
    $\begingroup$ I'm trying to understand the goal you have in mind. Android Studio is used to make apps for the Android platform. As far as I know Mathematica is not (yet) available for that platform, but I may have missed the announcement. $\endgroup$ – Sjoerd C. de Vries Oct 4 '16 at 19:32
  • $\begingroup$ @SjoerdC.deVries, I want to use a theorem that is only available on Mathematica (VAS theorem for root isolation) and I am trying to combine these two tools in order to get a result. Have you heard about any other tool-program that could help me? $\endgroup$ – Maria Tsourma Oct 4 '16 at 22:32
  • 2
    $\begingroup$ Sorry, no. The point I was trying to make is that I don't understand how your idea was ever going to work. I assume that Studio is simulating an Android environment for which a Wolfram Engine is not yet available. So I don't see how you could link to it. $\endgroup$ – Sjoerd C. de Vries Oct 5 '16 at 5:54

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.