there is an IDL class file which contains object of another IDL class file and i want to use that the inner class object and assign it a string value

StackOverflow https://stackoverflow.com/questions/16856271

  •  30-05-2022
  •  | 
  •  

Question

Here TP_DSCVoyChange class has KEY_DSC as an attribute we want to populate this KEY_DSC value from Java using a String value using TP_DSCVoyChange constructor. Eg. voyagelist.addElement(new TP_DSCVoyChange(dscDetails.strDscKey,dscDetails.voyage));

but an error occurs that dscDetails.strDscKey is a String and not of type KEY_DSC.

Can you please let me know how to fix it?

public final class TP_DSCVoyChange implements IDLEntity
{

    public KEY_DSC key;
    public String voyNumbers[];
    private transient Hashtable _printMap;
    private transient Hashtable _cmpMap;

    public TP_DSCVoyChange()
    {
        _printMap = null;
        _cmpMap = null;
    }

    public TP_DSCVoyChange(KEY_DSC key_dsc, String as[])
    {
        _printMap = null;
        _cmpMap = null;
        key = key_dsc;
        voyNumbers = as;
    }

    public String toString()
    {
        StringBuffer stringbuffer = new StringBuffer("struct idl.TP_DSCVoyChange {");
        Thread thread = Thread.currentThread();
        boolean flag = false;
        if(_printMap == null)
        {
            synchronized(this)
            {
                if(_printMap == null)
                {
                    flag = true;
                    _printMap = new Hashtable();
                }
            }
        }
        if(!flag && _printMap.get(thread) != null)
        {
            stringbuffer.append("...}");
            return stringbuffer.toString();
        }
        _printMap.put(thread, this);
        stringbuffer.append("\n");
        stringbuffer.append("idl.KEY_DSC key=");
        stringbuffer.append(key);
        stringbuffer.append(",\n");
        stringbuffer.append("java.lang.String[] voyNumbers=");
        stringbuffer.append("{");
        if(voyNumbers == null)
        {
            stringbuffer.append(voyNumbers);
        } else
        {
            for(int i = 0; i < voyNumbers.length; i++)
            {
                stringbuffer.append(voyNumbers[i] == null ? null : (new StringBuilder()).append('"').append(voyNumbers[i]).append('"').toString());
                if(i < voyNumbers.length - 1)
                {
                    stringbuffer.append(",");
                }
            }

        }
        stringbuffer.append("}");
        stringbuffer.append("\n");
        _printMap.remove(thread);
        stringbuffer.append("}");
        return stringbuffer.toString();
    }

    public boolean equals(Object obj)
    {
        if(this == obj)
        {
            return true;
        }
        if(obj == null)
        {
            return false;
        }
        Thread thread = Thread.currentThread();
        boolean flag = false;
        if(_cmpMap == null)
        {
            synchronized(this)
            {
                if(_cmpMap == null)
                {
                    flag = true;
                    _cmpMap = new Hashtable();
                }
            }
        }
        if(!flag)
        {
            Object obj1 = _cmpMap.get(thread);
            if(obj1 != null)
            {
                return obj == obj1;
            }
        }
        if(obj instanceof TP_DSCVoyChange)
        {
            _cmpMap.put(thread, obj);
            TP_DSCVoyChange tp_dscvoychange1 = (TP_DSCVoyChange)obj;
            boolean flag1 = true;
            flag1 = key == tp_dscvoychange1.key || key != null && tp_dscvoychange1.key != null && key.equals(tp_dscvoychange1.key);
            if(flag1 && (flag1 = voyNumbers.length == tp_dscvoychange1.voyNumbers.length))
            {
                for(int i = 0; flag1 && i < voyNumbers.length; i++)
                {
                    flag1 = voyNumbers[i] == tp_dscvoychange1.voyNumbers[i] || voyNumbers[i] != null && tp_dscvoychange1.voyNumbers[i] != null && voyNumbers[i].equals(tp_dscvoychange1.voyNumbers[i]);
                }

            }
            _cmpMap.remove(thread);
            return flag1;
        } else
        {
            return false;
        }
    }
}



public final class KEY_DSC implements IDLEntity
{

    public int dsc;

    public KEY_DSC()
    {
    }

    public KEY_DSC(int i)
    {
        dsc = i;
    }

    public String toString()
    {
        StringBuffer stringbuffer = new StringBuffer("struct idl.KEY_DSC {");
        stringbuffer.append("\n");
        stringbuffer.append("int dsc=");
        stringbuffer.append(dsc);
        stringbuffer.append("\n");
        stringbuffer.append("}");
        return stringbuffer.toString();
    }

    public boolean equals(Object obj)
    {
        if(this == obj)
        {
            return true;
        }
        if(obj == null)
        {
            return false;
        }
        if(obj instanceof KEY_DSC)
        {
            KEY_DSC key_dsc = (KEY_DSC)obj;
            boolean flag = true;
            flag = dsc == key_dsc.dsc;
            return flag;
        } else
        {
            return false;
        }
    }
}
Was it helpful?

Solution 2

   Vector voyagelist =new Vector(); 
   int dsc =Integer.parseInt(dscDetails.strDscKey);
   KEY_DSC keyDSC = new KEY_DSC(dsc); 
   System.out.println(keyDSC.toString()); 
   voyagelist.addElement(new TP_DSCVoyChange(keyDSC,dscDetails.voyage));

since KEY_DSC class has a constructor that takes int parameter then converting string into int and passing it to the ctor resolves the issue.

OTHER TIPS

These

public TP_DSCVoyChange() {/* [...] */}
public TP_DSCVoyChange(KEY_DSC key_dsc, String as[]) {/* [...] */}

are your ctors, but this

TP_DSCVoyChange(dscDetails.strDscKey,dscDetails.voyage)

is how you call it. So you try to provide

dscDetails.strDscKey

which is apparently a String, for the first formal argument of a ctor which simply does not exist - the first formal argument of "B", which is the ctor you apparently want to use, is of type "KEY_DSC", which is not String, nor one of its descendants.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top