Unable to Cast a Object into Typed Class

Hi, I am not able to cast a simple object in typed class.
I have a class ItemVO.as
package
    public class ItemVO
        public var idData:String;
        public var valData:String;
In application on some action
            var obj:Object = new Object;
            obj['idData']="001";
            obj['valData']="abhinav";
            try{
                var itemVO:ItemVO=ItemVO(obj);
            }catch(e:Error)
                Alert.show(e.message);
I am getting below error at var itemVO:ItemVO=ItemVO(obj)
Error #1034: Type Coercion failed: cannot convert Object@b5c3ad9 to ItemVO.
Where I am doing wrong??
Please help.
Thanks.
Abhinav

You need to do it by hand.
Or make ItemVO able to take an object as constructor argument. Which is again doing it by hand.
public function ItemVO(obj:Object)
    idData = obj.idData;
    valData = obj.valData;
C

Similar Messages

  • How to cast an Object into a specific type (Integer/String) at runtime

    Problem:
    How to cast an Object into a specific type (Integer/String) at runtime, where type is not known at compile time.
    Example:
    public class TestCode {
         public static Object func1()
    Integer i = new Integer(10); //or String str = new String("abc");
    Object temp= i; //or Object temp= str;
    return temp;
         public static void func2(Integer param1)
              //Performing some stuff
         public static void main(String args[])
         Object obj = func1();
    //cast obj into Integer at run time
         func2(Integer);
    Description:
    In example, func1() will be called first which will return an object. Returned object refer to an Integer object or an String object. Now at run time, I want to cast this object to the class its referring to (Integer or String).
    For e.g., if returned object is referring to Integer then cast that object into Integer and call func2() by passing Integer object.

    GDS123 wrote:
    Problem:
    How to cast an Object into a specific type (Integer/String) at runtime, where type is not known at compile time.
    There is only one way to have an object of an unknown type at compile time. That is to create the object's class at runtime using a classloader. Typically a URLClassloader.
    Look into
    Class.ForName(String)

  • Production Order Error: "Unable to cast COM object of type 'System.__ComObj

    Hi all,
    I have the following code:
    Dim oProdOrders As SAPbobsCOM.Documents
    oProdOrders = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders)
    after the second line I get a system exception: {"Unable to cast COM object of type 'System.__ComObject' to interface type 'SAPbobsCOM.Documents'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A6DA575B-E105-4585-9F4B-50CC4044EEDD}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."}     
    If I change document to eg oQuotations it proceeds normally.
    Any Idea?
    Thanks in advance,
    Vangelis

    try it as
    Dim oProdOrders As SAPbobsCOM.ProductionOrders
    oProdOrders = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders)

  • How to cast an object to a class known only at runtime

    I have a HashMap with key as a class name and value as the instance of that class. When I do a 'get' on it with the class name as the key, what I get back is a generic java.lang.Object. I want to cast this generic object to the class to which it belongs. But I don't know the class at compile time. It would be available only at runtime. And I need to invoke methods on the instance of this specifc class.
    I'm not aware of the ways to do it. Could anybody suggest/guide me how to do it? I would really appreciate.
    Thanks a lot in advance.

    Thanks all for the prompt replies. I am using
    reflection and so a generic object is fine, I guess.
    But a general question (curiosity) specific to your
    comment - extraordinarily generic...
    I understand there's definitely some overhead of
    reflection. So is it advisable to go for interface
    instead of reflection?
    Thanks.Arguments for interfaces rather than reflection...
    Major benefit at run-time:
    Invoking a method using reflection takes more than 20 times as long without using a JIT compiler (using the -Xint option of Java 1.3.0 on WinNT)... Unable to tell with the JIT compiler, since the method used for testing was simple enough to inline - which resulted in an unrealistic 100x speed difference.
    The above tests do not include the overhead of exception handling, nor for locating the method to be executed - ie, in both the simple method invocation and reflective method invocations, the exact method was known at compile time and so there is no "locative" logic in these timings.
    Major benefit at compile-time:
    Compile-time type safety! If you are looking for a method doSomething, and you typo it to doSoemthing, if you are using direct method invocation this will be identified at compile time. If you are using reflection, it will compile successfully and throw a MethodNotFoundException at run time.
    Similarly, direct method invocation offers compile-time checking of arguments, result types and expected exceptions, which all need to be dealt with at runtime if using reflection.
    Personal and professional recommendation:
    If there is any common theme to the objects you're storing in your hashtable, wrap that into an interface that defines a clear way to access expected functionality. This leaves implementations of the interface (The objects you will store in the hashtable) to map the interface methods to the required functionality implementation, in whatever manner they deem appropriate (Hopefully efficiently :-)
    If this is feasible, you will find it will produce a result that performs better and is more maintainable. If the interface is designed well, it should also be just as extensible as if you used reflection.

  • Unable to insert pdf object into ppt or word

    I am unable to insert a pdf object into Word or Powerpoint.  I have Adobe Reader 9.3 and Windows 7 MS Office 2010 64 bit.   Previously, I was able to perform this task without issue with the same software. 
    For word, I get:
    "The program used to create this object is AcroExch.  That program is either not installed on your computer or it is not responding.  The edit this object install AcroExch or ensure that any dialog boxes in AcroExch are closed". 
    For Powerpoint, I get:
    "The server application, source file, or item can't be found, or returned an unknown error.   You mayneed to reinstall the server application." 
    Was an update sent out that may have caused the issue? 
    Or is there a solution to resolve the issue?  The ony solution I have sound is Disabling Protect Mode which does not apply to this version of Reader. 
    Any help would be greately appreciated.  Thank you.

    There is another thread on this and seems to be an ongoing issue with neither Microsoft nor Adobe owning up to it.  What I did to work-around the issue is create a .zip file of the .pdf file which can then be put into the workd doc as an object file icon.  Worked for me.  Not the best solution but this has been ongoing since 2011, and this worked.

  • Passing objects into a class constructor

    I've created a frame for inputting a patient's medical results. There are lots of buttons for temperature, blood pressure, etc. I've created a separate, inner class that creates a NumberPad frame to enter the patient's results. Press the "Temp." button, for example, a NumberPad appears, you enter the temperature, press the "Enter" button on the NumberPad and the number appears in a Label next to the "Temp." button.
    The problem is that I've written the constructor of the NumberPad with a label parameter so that the right label gets updated. e.g.
    class NumberPad extends Frame implements ActionListener
    public NumberPad(Label aLabel)
    However, because I've implemented ActionListener, I've had to override the actionPerformed method and I don't know how to pass the aLabel object that I give to the NumberPad constructor into the actionPerformed method so that, for example
    public actionPerformed(ActionEvent evt)
    String s = evt.getActionCommand
    if (s.equals("ENTER")
    aLabel.setText(display of numberpad);
    How do I transfer the aLabel object into the actionPerformed method so that the correct label gets updated?

    Store the label as an instance variable.
    class NumberPad extends Frame implements ActionListener {
        private Label aLabel;
        public NumberPad(Label aLabel) {
            this.aLabel = aLabel;
        public actionPerformed(ActionEvent evt) {
            String s = evt.getActionCommand;
            if (s.equals("ENTER") {
                aLabel.setText(display of numberpad);
    }[/code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Unable to insert pdf object into 64-bit Word 2010

    I have always been able to insert pdf files into word documents.  However, when I upgraded to the 64-bit version of Word, I started experiencing the below issue.
    My setup is: Windows 7 64-bit, Word 2010 64-bit, Adobe Acrobat 9 Pro v9.4.7.
    When I attempt to insert a pdf file into Word, I receive the following message:
    "The program used to create this object is AcroExch.  That program is either not installed on your computer or it is not responding.  To edit this object, install AcroExch or ensure that any dialog boxes in AcroExch are closed."
    I have researched this issue a great deal. 
    Previously, I found a posting which specified some registry keys to delete.  I followed these directions and it worked.  But, after installing some updates, the issue is back and I am unable to find the post specifying the registry keys to remove.
    Any help will be greatly appreciated.
    Thanks!
    Brandon

    Solution:
    Open Adobe Reader / Pro
    Go to Edit àPreferenceà General (LHS)àUncheck “Enable protected mode at startup”.
    Adobe Reader’s protected mode will be disabled
    Now try inserting Adobe document in Word, it will work.  

  • Unable to insert PDF object into Word 2013

    Hi,
    While trying to insert PDF (Adobe Reader X 10.1.0) document into Word
    (Microsoft office Professional plus 2013 15.0.4420.1017) getting below error.
    Error Message: The Program used to create this object is
    Acroexch.That program is either not installed on your computer or it is not
    responding, to edit this object , install AcroExch to ensure that any dialog
    boxes in Acroexch are closed
    Also i tried mentioned steps:
    Step1: Open Adobe Reader and goto Edit ==> References (ctrl+k).
    Step2: In General uncheck the Enable protected mode at startup.
    But still getting the same error.
    Any suggestion Please!!!!!!!
    Thanks in advance.

    gkrish wrote:
    (Adobe Reader X 10.1.0)
    I would try to install a newer Reader version; either 10.1.10 or 11.0.07.

  • Putting a Class Object into a Vector

    HI all
    I need to put a class object into another classes vector, then be able to read it and retrieve data.
    I can put the object into the vector but all i seem to be able to retrieve is data like Account@2343c2.
    Is this some sort of tag? How do i get to the data?
    thankz
    joey

    That's what you get when you print an object which does not have its own toString() method to do anything different - it picks up the Object class's toString method instead. For example:
    System.out.println(new Object());It sounds like you're doing something like this:
    Vector v = new Vector();
    v.add(new Account(42));If you were to do the following, you would see that sort of output:
    System.out.println(v.get(0));The appropriate way to do this would be something like the following:
       // Use a List reference instead of a Vector reference, and create
       // an ArrayList object in preference to a Vector object
       List list = new ArrayList();
       list.add(new Account(42));
       // Iterate through the list of accounts - use an
       // iterator because this prevents off-by-one errors
       // that arise with direct indexing.
       Iterator i = list.iterator();
       while(i.hasNext()) {
          // Cast the reference returned by the iterator from
          // Object to Account so that we can call account-specific
          // methods.
          Account current = (Account)i.next();
          // Call the method specific to the Account class (getBalance
          // is just an example that I made up).
          System.out.println(current.getBalance());
       }

  • Question about casting objects into Number

    This might sound a bit silly, but i have a function that
    casts an Object into a Number and then checks if it is NaN to
    ensure that it is indeed a number, it returns true if it is a valid
    number or false if it isn't a number
    Now i have a TextInput and when i type for example "HELLO"
    and call the function it returns false (since that is not a
    number), if i type 23 it returns true (it is a number), if i type
    "20a" it returns false. Everything works fine except for one
    combination, if i type any number and the letter "e", for example
    2e, 9E, 5e, etc, it returns true, which means this is a valid
    Number, why is this?

    I thought it might be that, but for my bussiness logic, 2e is
    not a valid number.......will i need to parse the string and
    validate it?

  • How to cast to a user given class..

    Hi all....
    Can u help me to create a generic method which take a class name
    as String and cast one object to this class type and return.
    Note :class name is provided as String.

    Hi Suresh.... you can't do such a thing.
    public class Foo {
         public static Object castTo(Object obj, String className) throws Exception {
              Class clazz     = Class.forName(className);
              return clazz.cast(obj);
         public static void main(String[] args) throws Exception {
              Test2 s = new Test2();
              Object o = castTo(s, "Test1");
              System.out.println(o);
    class Test1 {
         public String toString(){
              return this.getClass().toString();
    class Test2 extends Test1 { }

  • How to pass the object of one class to the another class?

    Hello All,
    My problem is i am sending the object of serializable class from one class to another class but when i collection this class into another it is transfering null to that side even i filled that object into the class before transfer and the point is class is serializable
    code is below like
    one class contain the code where i collecting the object by calling this function of another class:-
    class
    lastindex and initIndex is starting and ending range
    SentenceStatusImpl tempSS[] = new SentenceStatusImpl[lastIndex-initIndex ];
    tempSS[i++] = engineLocal.CallParser(SS[initIndex],g_strUserName,g_strlanguage,g_strDomain);
    another class containg code where we transfering the object:-
    class
    public SentenceStatusImpl CallParser(SentenceStatusImpl senStatus, String strUserName, String strLanguage, String strDomain)
    *//here some code in try block*
    finally
    System.+out+.println("inside finally...........block......"+strfinaloutput.length);
    senStatus.setOutputSen(strfinaloutput);//strfinaloutput is stringbuffer array containg sentence
    fillSynonymMap(senStatus);
    senStatus.setTranslateStatus(*true*);
    return senStatus;
    Class of which object is serialized name sentenceStatusimpl class:-
    public class SentenceStatusImpl implements Serializable
    ///Added by pavan on 10/06/2008
    int strSourceSenNo;
    String strSourceSen = new String();
    String strTargetSen = new String();
    StringBuffer[] stroutputSen = null;
    HashMap senHashMap = new HashMap();
    HashMap dfaMarkedMap = new HashMap();
    boolean bTargetStatus = false;
    public SentenceStatusImpl(){
    public void setOutputSen(StringBuffer[] outputSen){
    stroutputSen = outputSen;
    public StringBuffer[] getOutputSen(){
    return stroutputSen;
    public void setTranslateStatus(*boolean* TargetStatus){
    bTargetStatus = TargetStatus;
    }//class

    ok,
    in class one
    we are calling one function (name callParser(object of sentenceStatusImpl class,.....argument.) it return object of sentenceStatusImple class containg some extra information ) and we collecting that object into same type of object.
    and that sentenceStatusImple classs implements by Serializable
    so it some cases it is returning null
    if you think it is not proper serialization is please replay me and suggest proper serialization so that my work is to be done properly (without NULL)
    hope you understand my problem

  • Unable to cast object of type 'Oracle.DataAccess.Types.OracleDecimal'......

    I have some Oracle Tables with sequences for primary key and stored procs in packages to wrap up the insert commands. The sequences field are all declared as NUMBER.
    I also have Datasets based on the tables and a DataAdapter for each package. The Datasets see the primary keys as System.Decimal. The DataAdapter sees the output primary key parameter to the stored procs as OracleDecimal.
    tmp.Parameters.Add(new OracleParameter("P_ID", Oracle.DataAccess.Client.OracleDbType.Decimal, ParameterDirection.Output));
    tmp.Parameters["P_ID"].SourceColumn = "ID";
    When I call the Update on the DataAdapter the update happens on the DB and then I get the following error
    System.ArgumentException : Unable to cast object of type 'Oracle.DataAccess.Types.OracleDecimal' to type 'System.IConvertible'.Couldn't store <231> in ID Column. Expected type is Decimal.
    ----> System.InvalidCastException : Unable to cast object of type 'Oracle.DataAccess.Types.OracleDecimal' to type 'System.IConvertible'.
    If I change the Oracle parameter to Oracle.DataAccess.Client.OracleDbType.Int32 or Oracle.DataAccess.Client.OracleDbType.Int64 it works fine - any ideas why that would be ? I would expect System.Decimal to map to Oracle.DataAccess.Types.OracleDecimal.

    Hi,
    If I change the Oracle parameter to Oracle.DataAccess.Client.OracleDbType.Int32 or Oracle.DataAccess.Client.OracleDbType.Int64 it works fine - any ideas why that would be ? I would expect System.Decimal to map to Oracle.DataAccess.Types.OracleDecimal.
    I'm trying to do the same, but no matter what I do, I get the OracleDecimal error. Parameter is defined as:
    bq. this._adapter.InsertCommand = new global::Oracle.DataAccess.Client.OracleCommand(); \\ this._adapter.InsertCommand.Connection = this.Connection; \\ this._adapter.InsertCommand.CommandText = "INSERT INTO PERSON\r\n                      (ID, SURNAME, NAME, BIRTHCITY, EMSO)\r\nV" + \\ +"ALUES (:ID, :SURNAME, :NAME, :BIRTHCITY, :EMSO) RETURNING ID INTO :ID";+ \\ this._adapter.InsertCommand.CommandType = global::System.Data.CommandType.Text; \\ param = new global::Oracle.DataAccess.Client.OracleParameter(); \\ param.ParameterName = "ID"; \\ param.DbType = global::System.Data.DbType.Int32; \\ param.OracleDbType = global::Oracle.DataAccess.Client.OracleDbType.Int32; \\ param.Direction = global::System.Data.ParameterDirection.Output; \\ param.IsNullable = true; \\ param.SourceColumn = "ID"; \\ this._adapter.InsertCommand.Parameters.Add(param);
    But no luck...

  • Unable to cast object of type ?

    Hi ,
    i try to compile sample aspx page using plugin but it throws the error
    Unable to cast object of type 'asp.catalog_sample_aspx' to type 'netpoint.classes.NPbasepage'
    why this type error shows?
    pls guide me.

    here is an example of a page that inherits NPBasePage.
    <%@ Page Language="C#" MasterPageFile="~/masters/common.master" Inherits="netpoint.classes.NPBasePage" %>
    <%@ Import Namespace="netpoint.classes" %>
    <%@ Import Namespace="netpoint.api.account" %>
    <asp:Content ContentPlaceHolderID="mainslot" runat="server" ID="main">
        <asp:PlaceHolder ID="phMainSlot" runat="server">
            <scrip t language="c#" runat="server"> 
                protected void Page_Load(object sender, System.EventArgs e)
                    NPBasePage bp = (NPBasePage)Page;
                    NPUser u = new NPUser(bp.UserID);
                    txtBox.Text = u.FirstName + " " + u.LastName;
            </script>
            <div>
                <asp:TextBox ID="txtBox" runat="server"></asp:TextBox>
            </div>
        </asp:PlaceHolder>
    </asp:Content>

  • UNABLE TO CAST OBJECT OF TYPE 'PROFILECOMMON' TO TYPE 'PROFILECOMMON'

    I have four web application configured on the IIS with .Net Framework 2.0
    All the applications are working fine except one.
    If the system / server, restarted. The Application throws an error message "UNABLE TO CAST OBJECT OF TYPE 'PROFILECOMMON' TO TYPE 'PROFILECOMMON'"
    When I searched for the issue, they have mentioned that the temporary
    Profile class clashes with your ProfileCommon class.
    By setting <profile enabled="false"> you are telling it to NOT generate the dynamic, temporary Profile
    class and use your own instead.
    On every restart, I need to change the attribute value to make it work.
    Can you please let me know, why it crashed on server restart? How it can be resolved ?
    Root cause???
    Please help on this.
    MJ - Man of Joy (Rajkumar) Techno Geek

    Hello,
        Try located at c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\<your app name>\87f549dc\aa62540\Sources_App_Code\profile.cdcab7d2.cs 
    This temporary Profile class clashes with your ProfileCommon class. By setting <profile enabled="false"> you are telling it to NOT generate the dynamic, temporary Profile class and use your own instead.
     if the reply help you mark it as your answer.
     Free Managed C#
    Word,  PDF , Excel Component(Create,
    Modify, Convert & Print) 

Maybe you are looking for

  • Embedded Audio & Firefox

    I have Dreamweaver CS3. I used the insert media plugin feature to embed an MP3 file. I set the controls to be small, but visible. It works fine in Internet Explorer 7. It doesn't even show up or play in Firefox. In addition, if you select it in desig

  • Convert XML to JTree

    Hey, Does anyone have any code on how to convert an XML file into a JTree. I also need to be able to convert a JTree into XML. Any help would be great!

  • Macbook Air keeps crashing when going to sleep

    Everytime my air goes to sleep it doesn't. Anyway when I go to log back on, it won't wake up, then when I finally manage to get the screen to appear again it tells me 'your computer restarted due to an issue. press any button to continue' and I'm pre

  • Set Media to Archive Status

    Aloha Everyone- I have a workflow that has worked well for us to archive to LTO tape and I would like to continue this workflow if possible. I copy my data to a raid and place it into a folder called LTO001 etc. I import these files into Final Cut Se

  • 10.3 using afp to connect to windows 2000 share

    Here is my problem, I have two machines running 10.3 when I click on go - connect to server and enter my server that I want to connect to it tells me it could not connect to the server becuase the username or password is incorrect. What file do I nee