Create a Java Application with MATLAB Code in Android studio java
3 views (last 30 days)
Show older comments
i followed the instructions in this link in order to convert a matlab function and use it in java https://www.mathworks.com/help/compiler_sdk/gs/create-a-java-application-with-matlab-code.html
it works in NetBeans IDE but when i repeat the same steps in Android studio java this error massage appeared
Exception in thread "main" java.lang.ClassNotFoundException: com.example.asus.testttt.MakesqrClass
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
0 Comments
Answers (1)
Walter Roberson
on 9 May 2017
Edited: Walter Roberson
on 9 May 2017
The java code created with MATLAB Compiler SDK can only be used on the same operating system that it was compiled on.
In general, the output of MATLAB Compiler SDK can only ever run on the same operating systems that MATLAB itself can run on.
MATLAB Compiler SDK does not convert all of the MATLAB code to Java.
Instead, it uses the same technology as MATLAB Compiler in order to translate the MATLAB code into threaded interpreted code -- interpreted code that needs MCR (MATLAB Component Runtime) to execute. Then MATLAB Compiler SDK wraps the calls into MCR into some JNI (Java Native Interface) code and builds a .jar from that.
The invoking Java program calls into the .jar, which uses the JNI to execute operating-system-specific machine-code MCR, and MCR interprets the threaded interpreted code.
MATLAB itself runs MATLAB programs by translating them into threaded interpreted code that is then interpreted using operating-system dependent libraries. The single biggest difference between MATLAB interactive execution and how compiled MATLAB programs work is that compiled MATLAB programs do not have access to the command line interpreter; otherwise the execution path is nearly identical. (This is the main reason why programs produced by MATLAB Compiler and MATLAB Compiler SDK work at nearly the same speed as the interactive MATLAB, because they execute the same way.)
The consequence of all of this is that programs produced by MATLAB Compiler or MATLAB Compiler SDK can only potentially execute on systems that MCR has been built for -- which is to say MS Windows, OS-X, or (general purpose) Linux. There is no MCR for Android.
3 Comments
Walter Roberson
on 9 May 2017
MATLAB Coder is able to compile a subset of MATLAB into C or C++. That subset is missing most of the graphics, which might or might not be important to you.
The most complete ability to use MATLAB with Android is to create a Simulink model and use Android specific blocks.
See Also
Categories
Find more on Setup and Configuration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!