2 lizhizuoyongzhe lizhizuoyongzhe 于 2015.05.29 17:21 提问

为什么我在matlab上写的程序打成jar包 导入java程序运行就出错 1C

package testGraph;

//import paintgraph.MatlabPaint;
import com.mathworks.toolbox.javabuilder.MWException;

import toAdd.Adds;

public class TestPaint {

/**
 * @param args
 */
public static void main(String[] args) {
    Adds a;
    try {
        a = new Adds();
        Object[] b=new Object[2];
        b[0]=a.paint(1, 1,2);
    } catch (MWException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}

Exception in thread "main" java.lang.ExceptionInInitializerError
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getMCRRoot(MCRConfiguration.java:92)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ModuleDir.(MCRConfiguration.java:66)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getModuleDir(MCRConfiguration.java:71)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.(MWMCR.java:1571)
at toAdd.ToAddMCRFactory.(ToAddMCRFactory.java:99)
at toAdd.Adds.(Adds.java:61)
at testGraph.TestPaint.main(TestPaint.java:16)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1938)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.get(MCRConfiguration.java:85)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.(MCRConfiguration.java:87)
... 7 more

不知道为什么 看了下jdk的版本是java 1.6.0_20 matlab的java版本是 java 1.6.0_12_b04

3个回答

testcs_dn
testcs_dn   Rxr 2015.05.31 06:56

at testGraph.TestPaint.main(TestPaint.java:16行)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
索引越界了。

LogicTeamLeader
LogicTeamLeader   2015.06.03 16:32

你用matlab生成的jar包中的类是什么?是不是那个toAdd.Adds?

 at toAdd.ToAddMCRFactory.(ToAddMCRFactory.java:99)
at toAdd.Adds.(Adds.java:61)
at testGraph.TestPaint.main(TestPaint.java:16)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1

这里已经说了,String数组越界,是不是那个toAdd.Adds类的问题?

guonan198811
guonan198811   2015.06.03 18:38

一个是数组越界问题,还有就是在Java下和C#下运行MATLAB程序的时候,数据类型要做相应的转化,转化成JAVA支持的类型

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!