keyandahunzi 2021-05-28 08:58 采纳率: 0%
浏览 39

java调用c++的dll文件时,返回数据出现错误,求大神解答!!!

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7b1bc10f, pid=20208, tid=0x00002dfc
#
# JRE version: Java(TM) SE Runtime Environment (8.0_281-b09) (build 1.8.0_281-b09)
# Java VM: Java HotSpot(TM) Client VM (25.281-b09 mixed mode windows-x86 )
# Problematic frame:
# C  [hotrolling98.DLL+0x5c10f]  output+0x7ff
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\����\�ʸ�\�����ַ�\����������Ŀ_20210422�汾\����������Ŀ\test02\hs_err_pid20208.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

 

 

 

 

 

c++端的程序:

void output(JQResults *jqRES1)
{
    //JQResults  jqRES;
    int recordCounts = 0;
    map<int, map<int, vector<available_order>>> ::iterator multitr;
    map<int, vector<available_order>>::iterator intertr;
    vector <available_order>::iterator inintertr;
    cout << "A0" << endl;
    for (multitr = out_put.begin(); multitr != out_put.end(); multitr++)
    {
        for (intertr = multitr->second.begin(); intertr != multitr->second.end(); intertr++)
        {
            for (inintertr = intertr->second.begin(); inintertr != intertr->second.end(); inintertr++)
            {
                JQResult * a=new JQResult;
                //判断是不是xunihetong,若是xunihetong只要输出合同重量 烫辊材标志
                if (inintertr->orderNo == "xunihetong" || inintertr->orderNo == "xunitangguncai")
                {
                    a->orderNo = inintertr->orderNo;
                    a->productDscr = " ";
                    a->urgencyOrderFlag = 0;
                    a->unprWt = inintertr->unprWt;
                    a->orderThick =0;
                    a->orderWidth = inintertr->orderWidth;
                    a->orExpectedDeliveryPeriod = 0;
                    a->hopeDeliveryDate = 0;
                    a->hardnessDegreeMic = " ";
                    //a->steelCategory = " ";
                    a->steel_id = " ";
                    //a->furnace_need = " ";
                    //a->cold_need = " ";
                    //a->roller_need = " ";
                    a->shopsignCode =" ";
                    a->userClass = " ";
                    //a->isHotRoller = inintertr->isHotRoller;//这里先注释掉
                }
                else//若不是xunihetong,则输出全部的值
                {
                    a->orderNo = inintertr->orderNo;
                    a->productDscr = inintertr->productDscr;
                    a->urgencyOrderFlag = inintertr->urgencyOrderFlag;
                    a->unprWt = inintertr->unprWt;
                    a->orderThick = inintertr->orderThick;
                    a->orderWidth = inintertr->orderWidth;
                    a->orExpectedDeliveryPeriod = inintertr->orExpectedDeliveryPeriod;
                    a->hopeDeliveryDate  = inintertr->hopeDeliveryDate;
                    a->hardnessDegreeMic = inintertr->hardnessDegreeMic;
                    //a->steelCategory = inintertr->steelCategory;
                    a->steel_id = inintertr->steel_id;
                    //a->furnace_need = inintertr->furnace_need;
                    //a->cold_need = inintertr->cold_need;
                    //a->roller_need = inintertr->roller_need;
                    a->shopsignCode = inintertr->shopsignCode;
                    a->userClass = inintertr->userClass;
                    //a->isHotRoller = inintertr->isHotRoller;//这里先注释掉
                }    
                jqRES1->jqRes[recordCounts] = a;
                recordCounts++;
            }
        }
    }
    cout << "A3" << endl;
    jqRES1->count = recordCounts;
    for (int i = 0; i < jqRES1->count; i++) 
    {
        cout << 1 << endl;
        cout<< jqRES1->jqRes[i]->orderNo <<"       "<<"i="<<i
            << jqRES1->jqRes[i]->productDscr <<"       "
            << jqRES1->jqRes[i]->urgencyOrderFlag << "       "
            << jqRES1->jqRes[i]->unprWt <<"       "
            << jqRES1->jqRes[i]->orderThick <<"       "
            << jqRES1->jqRes[i]->orderWidth <<"       "
            << jqRES1->jqRes[i]->orExpectedDeliveryPeriod<< "       "
            << jqRES1->jqRes[i]->hopeDeliveryDate<<"         "
            << jqRES1->jqRes[i]->hardnessDegreeMic <<"       "
            //<< jqRES1->jqRes[i]->steelCategory << "       "
            << jqRES1->jqRes[i]->steel_id << "       "
            //<< jqRES1->jqRes[i]->furnace_need <<"       "
            //<< jqRES1->jqRes[i]->cold_need <<"       "
            //<< jqRES1->jqRes[i]->roller_need <<"       "
            << jqRES1->jqRes[i]->shopsignCode <<"       "
            << jqRES1->jqRes[i]->userClass    << endl;
    }
    cout << "jqRES1->count:" << jqRES1->count << endl;

}
//最后的接口函数
extern "C" _declspec(dllexport) JQResults* totalMethod(JQOrders *jqorders, JQResults * jqRES)
{
    inputExchange(jqorders);
    split_order();//读可用合同,获取前欠合同(除去烫辊材合同),读烫辊材合同(前欠),读烫辊材合同(非前欠),非前欠合同(除去烫辊材合同)
    
    int Max_day = 30;
    int Max_turn = Max_day * 15;
    //读日产能信息,用检修计划更新后的日产能//读辊期产能
    read_capacity(Max_day, Max_turn);
    cout << "in" << endl;
    //这里无法进行一个好的分割,则无法提取几个标签
    //seq_userClass = userClass_split();//返回一个vector<string>

    //string a[9] = { "C11", "B12", "B11", "A12", "A11", "A10", "A08", "A05", "空" };
    //vector<string> seq_userClass_temp(a, a + 9);
    //seq_userClass = seq_userClass_temp;

    string a[9] = { "C11", "B12", "B11", "A12", "A11", "A10", "A08", "A05", "A00" };
    vector<string> seq_userClass_temp(a, a + 9);
    seq_userClass = seq_userClass_temp;

    cout << "da" << endl;
    day = 0;
    while (day < 30)
    {
        if (day_available_capacity[day]>0)
        {
            //cout << "day1.1" << endl;
            order_owed_decision();
            //cout << "day1.2" << endl;
        }
        if (day_available_capacity[day]>0)
        {
            //cout << "day2.1" << endl;
            order_current_decision();
            //cout << "day2.2" << endl;
        }
        if (day_available_capacity[day]>0)
        {
            cout << "合同全部生产完毕" << endl;
            cout << day << endl;
            cout <<turn << endl;
            break;
        }
        day++;
        cout << day << "  " << turn << endl;
    }
    cout << "6" << endl;
    cout << "现有合同生产完毕" << endl;
    cout << day << "and" << turn << endl;
    cout << "7" << endl;
    //output_order();
    output(jqRES);//赋值输出函数

    cout << "8" << endl;
    return jqRES;
}
 

 

 

 

java端的接口函数:

package jq;

import com.sun.jna.Native;
import com.sun.jna.Structure;
import com.sun.jna.Library;

public interface dllNewTestApi01 extends Library
{

    public static dllNewTestApi01 dta = (dllNewTestApi01) Native.loadLibrary("D:\\钢铁\\攀钢\\西昌钢钒\\西昌热轧项目_20210422版本\\西昌热轧项目\\Debug\\hotrolling98", dllNewTestApi01.class);

    /**
     * 订单结构体
     */
    public static class JQOrder extends Structure
    {
        public static class ByReference extends dllNewTestApi01.JQOrder implements Structure.ByReference{
        }

        public static class ByValue extends dllNewTestApi01.JQOrder implements Structure.ByValue{
        }
        //**************直接读表的***************//
        public String orderNo;//合同名
        public String productDscr;//产品名称
        public int urgencyOrderFlag;//紧急合同标志
        public double unprWt;//合同重量
        public double orderThick;//合同厚度
        public double orderWidth;//合同宽度
        public int orExpectedDeliveryPeriod;//合同期望交货期别
        public int hopeDeliveryDate;//期望交货日期
        public String hardnessDegreeMic;//合同硬度
        public String steelCategory;//产品类别
        public String steelGrade;//炼钢记号
        //public String furnace_need;//加热炉需求
        //public String cold_need;//冷轧需求
       // public String roller_need;//轧制需求
        public String shopsignCode;//产品牌号
        public String userClass;//客户级别
        public String isHotRoller;//烫辊材标记
    }

    /**
     * 订单集合
     */
    public static class JQOrders extends Structure
    {
        public static class ByReference extends dllNewTestApi01.JQOrders implements Structure.ByReference
        {
        }

        public static class ByValue extends dllNewTestApi01.JQOrders implements Structure.ByValue
        {
        }

        public JQOrder.ByValue[] orders = new JQOrder.ByValue[20000];
        public int count;

    }

    /**
     * 结果结构体
     */
    public static class  JQResult extends Structure
    {
        public static class ByReference extends dllNewTestApi01.JQResult implements Structure.ByReference{
        }

        public static class ByValue extends dllNewTestApi01.JQResult implements Structure.ByValue{
        }
        public String orderNo;//合同名
        public String productDscr;//产品名称
        public int urgencyOrderFlag;//紧急合同标志
        public double unprWt;//合同重量(合同欠量)
        public double order_thick;//合同厚度
        public double orderWidth;//合同宽度
        public int orExpectedDeliveryPeriod;//合同期望交货期别
        public int hopeDeliveryDate;
        public String hardnessDegreeMic;//合同硬度
        public String steelCategory;//产品类别
        public String steelGrade;//炼钢记号
        //public String furnace_need;//加热炉需求
        //public String cold_need;//冷轧需求
        //public String roller_need;//轧制需求
        public String shopsignCode;//产品牌号
        public String userClass;//客户级别
        public String isHotRoller;//烫辊材标记
    }
    /**
     * 结果集
     */
    public static class JQResults extends Structure
    {
        public static class ByReference extends dllNewTestApi01.JQResults implements Structure.ByReference{
        }

        public static class ByValue extends dllNewTestApi01.JQResults implements Structure.ByValue{
        }
        public JQResult.ByReference[] jqRes = new JQResult.ByReference[20000];
        public int count;
    }

    /**
     * 总的模型算法丢进各种输入 最终输出组批结果     * @return
     */
    JQResults.ByReference totalMethod(JQOrders.ByReference jqorders, JQResults.ByReference jqRES);
    //void FreeMemory();


}

java端的调用函数:

public static void main(String[] args)
{
    try {
        /**
         * 下面方法是从txt中获取输入信息
         */
        readOrderData();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    /**
     * 下面方法是将存到java实体类中的输入信息转换为算法需要的类型
     */
    exChangeOrders(orders);

    //定义组批算法结果
    dllNewTestApi01.JQResults.ByReference resJQResults = new dllNewTestApi01.JQResults.ByReference();

    //调用组批算法得到算法结果
    resJQResults = dllNewTestApi01.dta.totalMethod(jqOrs, resJQResults);
  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-07 17:37
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表