【问题标题】:I built a matlab code into a Java project, and now I am getting an error while running the java line of code that calls that matlab function我在 Java 项目中构建了一个 matlab 代码,现在在运行调用该 matlab 函数的 java 代码行时出现错误
【发布时间】:2012-07-01 07:38:43
【问题描述】:

我的 matlab 代码进行图像处理,我制作了 matlab 函数,它有 2 个图像作为输入。我编写了一个单独的 java 类来执行 matlab 的 imread 功能,即将 jpg 图像读入 3D 数组(它是一个 RGB 图像)。

import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import QRcode_java.*;
import com.mathworks.toolbox.javabuilder.*;


public class Driver {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        encoder_class x=null;     //encoder_class is the class built from the  
                                        //matlab function                         

        Object[] barcode2=null;         //output of matlab function
        barcode_image_class barcode;     //class to imread the jpg image input
        barcode= new barcode_image_class();
        original_photo_class original_photo;  
             //class to imread another image input
        original_photo= new original_photo_class();

        try {
            x= new encoder_class();
            barcode2=x.encoder_function(barcode, original_photo); 
//**ERROR!** /*encoder_function is the matlab function written by me. this line gives an //error as the following: 
//"The method encoder_function(List, List) in the type encoder_class 
//is not applicable for the arguments (barcode_image_class, original_photo_class)"*/

        } catch (MWException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

您能告诉我如何解决这个错误吗?是我的java代码有问题,还是matlab代码的导入有问题?我对Java很陌生,所以我无法弄清楚问题所在。谢谢!

【问题讨论】:

  • Complete stab-in-the-dark:如果您在对Arrays.asList 的调用中将参数包装到x.encoder_function 是否有帮助,即 x.encoder_function(Arrays.asList(barcode), Arrays.asList (original_photo));? (You'll need to import java.util.Arrays;`.)
  • 谢谢卢克!此代码删除了错误!但是现在我在使用 Matlab-Java 接口时遇到了一些问题:线程“主”java.lang.UnsatisfiedLinkError 中的异常:无法在 java.library.path 上找到 MATLAB Builder JA 所需的库 mclmcrrt7_15.dll。此库通常与 MATLAB 或 MCR 一起安装,它的缺失可能表明该安装或当前路径配置存在问题。此组件尝试使用的 MCR 版本是:7.15。
  • 我将系统设置中的路径更改为 ...\Files\Java\jdk1.6.0_33\bin 但由于我安装了 Java 版本 7,它没有使用版本 6。问题是 matlab 正在连接到版本 6,因此存在不兼容问题。我该如何解决这个问题?

标签: java matlab image-processing matlab-deployment matlab-compiler


【解决方案1】:

从你们那里,你们定义了一个方法encoder_function(List, List),它接受两个Lists 作为参数。您正在尝试使用一些不是 Lists 的参数来调用它,这就是编译器抱怨的原因。

要解决此问题,您必须:

  • 更改encoder_function(List, List) 定义以将barcode_image_classoriginal_photo_class 作为参数并相应地更新方法的代码

  • 找到将barcode_image_classoriginal_photo_class 转换为List 的方法(通过实现List 接口或在两个类中提供一些帮助方法将它们转换为Lists

【讨论】:

    猜你喜欢
    • 2015-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-08
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多