I intend to convert my MATLAB code into java. I am following this official documentation. But after compiling using javac
I am unable to complete the step 17.
When I run this from cmd java -classpath .;"C:\Program Files\MATLAB\MATLAB Runtime\v93\toolbox\javabuilder\jar\javabuilder.jar";makesqr.jar getmagic 5
I get the error: Exception in thread "main" java.lang.NullPointerException at getmagic.main(getmagic.java:36)
I am simply following the tutorial for now and do not understand what is happening inside the file getmagic.java.
import com.mathworks.toolbox.javabuilder.*;
import makesqr.*;
class getmagic
{
public static void main(String[] args)
{
MWNumericArray n = null;
Object[] result = null;
Class1 theMagic = null;
if (args.length == 0)
{
System.out.println("Error: must input a positive integer");
return;
}
try
{
n = new MWNumericArray(Double.valueOf(args[0]),
MWClassID.DOUBLE);
theMagic = new Class1();
result = theMagic.makesqr(1, n);
System.out.println(result[0]);
}
catch (Exception e)
{
System.out.println("Exception: " + e.toString());
}
finally
{
MWArray.disposeArray(n);
MWArray.disposeArray(result);
theMagic.dispose();
}
}
}
Error is at line 36: theMagic.dispose();