Error when calling a Matlab function from Java
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I am trying to do a simple adder in Java using a matlab function.
This is the Matlab code:
function [total] = adder(a, b)
total = a + b;
end
Then I am developing a GUI in Netbeans to ask these two addens in two JFrames, and getting the result in a third JFrame.
This is the first JFrame:
package apppruebasumador;
public class P01 extends javax.swing.JFrame {
static double adden1;
public P01() {
initComponents();
setLocationRelativeTo(null);
}
/...
private void botonNextActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
adden1 = Double.parseDouble(cajaSum1.getText().replace(',','.'));
P02 p2 = new P02();
p2.setVisible(true);
this.dispose();
System.out.println("Adden1: "+adden1);
}
/....
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new P01().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton botonNext;
private javax.swing.JFormattedTextField cajaSum1;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
And this would be the second JFrame:
package apppruebasumador;
import ProjAdder.*;
import com.mathworks.toolbox.javabuilder.*;
public class P02 extends javax.swing.JFrame {
static double aden2;
static double[][] total;
public P02() {
initComponents();
setLocationRelativeTo(null);
}
/...
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
adden2 = Double.parseDouble(cajaSum2.getText().replace(',','.'));
System.out.println("Adden2: "+adden2);
try{
ClasssAdder CA = new ClassAdder();
Object[] results = null;
results = CA.sumador(1, P01.adden1, P02.adden);
MWArray results = (MWNumericArray) results[0];
total = (double[][]) result.toArray();
}
catch(Exception e){System.out.println(e);}
PRes p3 = new PRes();
p3.setVisible(true);
this.dispose();
System.out.println("Total: "+total);
}
/...
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new P02().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JFormattedTextField cajaSum2;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
And it crashes in the try-catch loop with this error:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Failed to find the library mclmcrrt7_17.dll, required by MATLAB Builder JA, on java.library.path.
This library is typically installed along with MATLAB or the MCR, its absence may indicate an issue with that installation or the current path configuration.
The MCR version that this component is trying to use is: 7.17.
Then woud be a third JFrame with the result of the add.
I am using the 64b r2012b version of Matlab, Windows 64b, NetBeans IDE 7.1.2 and Java: 1.7.0_04; Java HotSpot™ Client VM 23.0-b21.
I made correctly the Java Package in Matlab with deploytool, and added its jar file from ...\ProyAdder\distrib\ProjAdder.jar to the Project Libraies in Netbeans. And I also added the Matlab javabuilder jar from: C:\Program Files\MATLAB\R2012a\toolbox\javabuilder\jar\javabuilder.jar. I tried to add too this jar: C:\Program Files\MATLAB\R2012a\toolbox\javabuilder\jar\win64\javabuilder.jar but it still does not work...
I read something about problems with compability between 32 bits and 64 bits, but I think I am always working with 64 bits.
Any idea what I am doing wrong? Please I need some help because I need tho fix this little example to continue with my tesis.
Thank you a lot
0 个评论
回答(1 个)
Yatin
2013-11-6
Hi,
Your program is looking for the MCR(Matlab Compiler Runtime)which needs to be installed on your machine in order to run the deployable. You can download the appropriate version of MCR from this link.
Once you install the MCR, make sure to have the MCR directory added on your system path (PATH environment variable in Windows) and also that it should come first on your path.
For additional details you can see the links below:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!