Instance of Objects

I try to save an instance of an object by creating a new object with the object's values at the time. I add the new object into a vector. When the value of the object changes, why does the new object in the vector also change? How could I store the instance as it is, not changing with when the object changes?
Thanks.

847604 wrote:
I finally figured it out why the values have been changing. I was using a mutildimensional array and did not clone like the other things. Only a deep copy of the array would really finish the deal. When I did, no problem anymore.
Thank you guys so much.
One thing that I want to make sure about the clone() though. Since Cloneable is an interface, if I only use return super.clone(), what would it do? Do I actually have to do the following?
@Override
public Object clone() throws CloneNotSupportedException()
Obj obj1 = (Obj) super.clone();
}That's what you want, with a couple of additional bits of information.
1) If your instance variables (non-static member variables) are all primitives and immutable objects, then that's all you need. However, if any of your instance variables are mutable reference types (like List or Date), then you'll probably want to explicitly copy those as well, to get a deep copy. (Of course, if you want your clone and original to refer to the same Date object, so that they both see changes to that object, then you wouldn't do that.)
2) Not sure if "Obj" is supposed to be Object. If it is, there's never a need to cast to Object.
3) Since 1.5, Java supports covariant return types, so you can declare clone() to return an instance of your class, rather than Object.
public class Foo implements Cloneable {
  private int i; // no need for explicit deep clone of primitive
  private String s; // no need for explicit deep clone of immutable object
  private Date d; // need to explicitly deep clone mutable object
  public Foo clone() {
    Foo foo = (Foo) super.clone();
    foo.d = new Date(d); // or = d.clone(), or whatever approach is appropriate for copying a Date object
}Likewise, if your Foo has any setters that can change any of its fields, then any class that has a Foo as a member would have to explicitly deep clone its Foo, which would then (by the above) take care of cloning its own mutable members.

Similar Messages

  • SSAS Tabular - Adding Column to a table gives error "Object reference not set to instance of object"

    If I make changes to a table in SSAS Tabular Visual Studio, the newly added column gives error as "Object
    reference not set to instance of object"

    Hi VikasJain13,
    According to your description, you get the "Object reference not set to instance of object" error when adding columns in Tabular. Right?
    Generally, it throws this error when the internal code is accessing the property of an empty object. As you mentioned it happens when you make changes on a table, mostly it means that table is already a empty object. Please re-process your tabular to see
    if this table is still existing. 
    If you have any question, please feel free to ask.
    Simon Hou
    TechNet Community Support

  • IDoc Error -Instance of object type could not be changed

    Hi All
    I am getting IDoc failed with the error massaeg "Instance of object type could not be changed"
    Message type :PORDCR
    Basic type : PORDCR05
    Message no. BAPI003
    Status : 51
    Please suggest on this
    Thanks
    Ajit

    Hi Madhu
    All these POs are uploaded during the Cutover Activities only, I am not sure whether it is uploaded through LSMW or not. What I guess is If its uploaded thrugh LSMW , then we can't change any value in the PO.
    Please sugest how can I process allthese IDocs.
    Thanks
    Ajit

  • IDoc failed with the error massaeg "Instance of object type could not be ch

    Hi All
    I am getting IDoc failed with the error massaeg "Instance of object type could not be changed"
    Message type :PORDCR
    Basic type : PORDCR05
    Message no. BAPI003
    Status : 51
    All POs are get uploaded in SAP during Cut over activities only.
    Please suggest on this.It will be a great help.
    Thanks
    Ajit

    Hi
    After uploading POs into SAP we are changing quantity and value in PO in Legacy system, and for this all IDocs are failed, subsequently these changes are not triggering to ECC.
    Please help
    Thanks
    Ajit

  • Cannot instance a object

    I have a problem. I cannot instance a object of my own class, anytime I try this my pc is hanging up it`s self.
    (The class is a little bit long for posting here and i do not have any idea were the mistake is.)
    Edited by: Michroe on Feb 2, 2009 7:34 AM

    ok i make the code easy as i can
    public calculating(int s1_new,int s2_new,int c1_new,int c2_new)
         s1 = s1_new;
         s2 = s2_new;
         c1 = c1_new;
         c2 = c2_new;
    public void sum()
         ms=s1*s2;
         c1 = s2*c1;
         c2 = s1*c2;
         ergcount = c1+c2;
         down();
       public void down()
                 while (ergcount >= ergsay)
                ergcount = ergcount-ergsay;
                erg = erg+1;
           if (ergcount == 0)
              System.out.println("result : "+erg); 
            ergcount = 0;
                 ergsay = 0;
                 erg = 0;    
             else
                 System.out.println("result : "+erg+" "+ergcount+"/"+ergsay);
                 ergcount = 0;
                 ergsay = 0;
                erg = 0;
            }I think the problem is about the down() method.

  • BAPI_PO_CRETE1:No instance of object type PurchaseOrder has been created

    Hi All,
    It's very urgent,can u plz guide me how to use <b>BAPI_PO_CRETE1</b>
    I am getting the folowing errorrs while creating,<b>esp the error 1</b>
    can u plz guide me what are all the parameters to to pass to suppress this error
    <b>1. No instance of object type PurchaseOrder has been created. External reference:</b>
    2. Purchase order still contains faulty items
    3. Please only use sites with local currency EUR
    4. Net price for item 00010 taken from conditions
    Thanks in advance.
    Best Regards,
    Vishnuvardhan reddy.

    there are mandotary fields in ur bapi that have to b filled in, and u have to check the item elemant of how many characters it requires if the data elemant if 5 charaters u have to fill in the precceding with a number of zero here is a sample code of creating a Po with a single line item
    REPORT zak_testing .
    CONSTANTS : c_x VALUE 'X'.
    ***Structures to hold PO schedule data
    **DATA : itemschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER *LINE ,
    **itemschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE .
    *Structures to hold PO header data
    DATA : header LIKE bapimepoheader ,
    headerx LIKE bapimepoheaderx .
    *Structures to hold PO account data
    DATA : account LIKE bapimepoaccount OCCURS 0 WITH HEADER LINE ,
    accountx LIKE bapimepoaccountx OCCURS 0 WITH HEADER LINE .
    *Internal Tables to hold PO ITEM DATA
    DATA : item LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,
    itemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE,
    *Internal table to hold messages from BAPI call
    return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
    *Internal table to hold messages from BAPI call
    pocontractlimits LIKE bapiesucc OCCURS 0 WITH HEADER LINE.
    DATA : w_header(40) VALUE 'PO Header',
    purchaseorder LIKE bapimepoheader-po_number,
    delivery_date LIKE bapimeposchedule-delivery_date.
    DATA : ws_langu LIKE sy-langu.
    header-comp_code = '01'.
    header-doc_type = 'NB'.
    header-vendor = '0000101111'.
    header-creat_date = sy-datum.
    header-purch_org = '0001'.
    header-pur_group = '502'.
    header-doc_date = sy-datum.
    *header-quot_date = sy-datum.
    *append header.
    *POPULATE HEADER FLAG.
    headerx-comp_code = c_x.
    headerx-doc_type = c_x.
    headerx-vendor = c_x.
    headerx-creat_date = c_x.
    headerx-purch_org = c_x.
    headerx-pur_group = c_x.
    headerx-doc_date = c_x.
    *populate ur item table
    item-po_item = '00010'. " note item in Quotes
    item-acctasscat = 'K'.
    item-short_text =  'workforce labour'.
    item-matl_group = '904045'.
    item-plant = '0002'. " depending if 0002 plant exist in ur database
    item-quantity = '1'.
    item-po_unit = 'EA'.
    item-net_price = '1000000'.
    item-price_unit = '1'.
    APPEND item.
    CLEAR item.
    *POPULATE ITEM FLAG TABLE
    itemx-po_item = '00010'. "notice that item has to b passes in every instance
    itemx-po_itemx = c_x.
    itemx-acctasscat = c_x.
    itemx-short_text = c_x.
    itemx-matl_group = c_x.
    itemx-plant = c_x.
    itemx-quantity = c_x.
    itemx-po_unit = c_x.
    itemx-net_price = c_x .
    itemx-price_unit = c_x.
    APPEND itemx.
    CLEAR itemx..
    itemx-material = c_x.itemx-net_price = c_x
    *POPULATE ACCOUNT DATA.
    account-po_item = '00010'.
    account-creat_date = sy-datum .
    account-gr_rcpt = 'MTCD FS'.
    account-unload_pt = 'Woodstock'.
    account-costcenter = '0000120010'.
    account-gl_account = '0000455655'.
    *account-CO_AREA    = 'MTCD FS'.
    account-serial_no = serial .
    APPEND account.
    CLEAR account.
    *POPULATE ACCOUNT FLAG TABLE.
    accountx-po_item = '00010'.
    accountx-po_itemx = c_x.
    accountx-creat_date = c_x .
    accountx-gr_rcpt = c_x.
    account-unload_pt = c_x.
    accountx-costcenter = c_x.
    accountx-gl_account = c_x .
    APPEND accountx.
    CLEAR accountx.
    APPEND itemx. CLEAR itemx.
    **POPULATE ITEM SCHEDULE DATA.
    **POPULATE ITEM FLAG FOR SCHEDULE TABLE.
    *BAPI CALL
    CALL FUNCTION 'DIALOG_SET_NO_DIALOG'.
    CALL FUNCTION 'BAPI_PO_CREATE1'
         EXPORTING
              poheader         = header
              poheaderx        = headerx
         IMPORTING
              exppurchaseorder = purchaseorder
         TABLES
              return           = return
              poitem           = item
              poitemx          = itemx
              poaccount        = account
              poaccountx       = accountx.
    *Confirm the document creation by calling database COMMIT
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
         EXPORTING
              wait = 'X'.
    IF NOT header IS INITIAL.
      CALL FUNCTION 'DEQUEUE_ALL'.
    ELSE.
      CALL FUNCTION 'DEQUEUE_ALL'.
    **message i036.
    ENDIF.
    try this n substitute the code where relavent

  • No instance of object type PurchaseRequisition has been created.External re

    Dear experts,
           I used the bapi:BAPI_PR_CREATE to create PR, occurs below error.
    No instance of object type PurchaseRequisition has been created. External reference: A0460-0013
    Can you tell me how to resolve ?
    CALL FUNCTION 'BAPI_PR_CREATE'
          EXPORTING
           PRHEADER                    = PRHEADER
           PRHEADERX                   = PRHEADERX
             TESTRUN                     = 'X'
           IMPORTING
            NUMBER                      =  PR_NO
            PRHEADEREXP                 =
            TABLES
             RETURN                      = PR_RETURN
              PRITEM                      = PRITEM
              PRITEMX                     = PRITEMX
              PRITEMEXP                   =  PRITEMEXP
            PRITEMSOURCE                =
             PRACCOUNT                   = PRACCOUNT
            PRACCOUNTPROITSEGMENT       =
            PRACCOUNTX                  = PRACCOUNTX
            PRADDRDELIVERY              = PRACCOUNTX
            PRITEMTEXT                  =
            PRHEADERTEXT                =
            EXTENSIONIN                 =
            EXTENSIONOUT                =
            PRVERSION                   =
            PRVERSIONX                  =
            ALLVERSIONS                 =

    Hi Merry,
    I think you are missing some of the mandatory fields for this BAPI, thats why you are getting this error.
    Check all the fields filled and also PRHEADERX, that have you filled X for all the fields filled in PRHEADER.
    Regards,
    Nitin.

  • No instance of object type PurchaseOrder has been created. External referen

    Hi Friends,
    We are on SRM 5.0 SP11, R/3 4.7 backend.
    When we try to create a PO manually in SRM PO doesnot get created, but we get this error message in application monitors of RZ20  - "No instance of object type PurchaseOrder has been created. External reference: "
    I have looked at the note 973952 but this is not applicable for our system.
    any help on this ???
    Regards,
    Kumar
    Edited by: Kumar on Apr 23, 2008 1:35 PM

    Hi all,
    @Dinesh: I have checked all the settings mentioned by you and they are in place.
    @David: the other errors following this issue are
    PurchOrder 0800000024: PO header data still faulty
    PO 0800000024: Document type ECPO not allowed with doc. category F (Please check input)
    PurchOrder 0800000024: Item category not allowed with document type ECPO.
    As suggested by Hitender, I tired to push the PO manually throgh the function module and now in RZ20 i get the error as PO 0800000024: Document number 800000024 not within defined inter val
    But I checked the number ranges in both the systems and they looks fine...
    This is ECS scenario:
    In SRM System I have maintained the number ranges for local PO as 08     0800000001     0899999999     800000030     
    and in R/3 08     0800000001     0899999999     800000030     X(ext flag selected).
    Please advice whether this is correct.. I have also checked the Document types item categories.....
    Regards,
    Kumar

  • Instance an Object which name is in a string

    hi, I've this problem:
    I must instance an Object, but the Object's type name is stored in a string. I could write a code similar to this:
    Object c = new "Car"();
    Someone can help me?

    sorry, but I don't understand very well....don't panic, doremisafolatido ( is that right? ) isgiving you an impromptu lesson in polymorphism!
    Close enough. :)
    He'll need polymorphism. If he couldn't
    construct a Car the normal way (without reflection),
    he won't be able to cast to one. If he writes the
    Car as follows, he can cast to a Runnable (I know you
    know this, but he seems not to).
    public class Car implements Runnable
    public void run() {
    // doSomething
    String name = "my.package.Car";
    Class clazz = Class.forName(name);
    Object obj = clazz.newInstance();
    ((Runnable)obj).run();
    I'd advise against using Runnable for anything other than threads. I've used Runnable in what seems like a perfectly acceptable situation, and it confused the hell out of everyone else on the project - they associate Runnable with threading, and couldn't get their head around what I was using it for. one of our technical leads got very upset that I was introducing threads to the code without good reason. It beggars belief that people in such high-profile positions couldn't tell the difference, but they couldn't, so I learnt not to use Runnable for anything other than passing to threads

  • BAPI 001 No instance of object type purchaseorder has been created

    Hello All,
    I get teh following error message in SC monitor (backend application error) as well as in RZ20. I tried to push into backend but no luck.Scenario Classic.SRM 5.0
    Shopping cart XXXXX(PO XXXXX) BAPI 001 No instance of object type purchaseorder has been created.
    The latest log in BBP_PD
    0000000001 I1111          Item in Transfer Process       X
    0000000001 I1112          Error in transmission
    Any clue is appreciated.
    Muthu
    Edited by: Muthuraman Govindasamy on Oct 7, 2008 2:59 PM

    Hi Andrea
    We can create a PO vis sourcing cockpit in classic mode.
    SC: Error in transmission BAPI 001
    Note :- 973952 and follow the Peter instructions. This error  message misleads
    regards
    Muthu

  • Error: No instance of object type PurchaseOrder has been created.

    Hi:
    I am using BAPI_PO_CREATE1 to create PO's using webdynpro. I get the following error message when I attempt to create a PO.
    No instance of object type PurchaseOrder has been created. External reference:
    Please help.
    Thanks
    Sriram

    Ramki:
    Yes, I did. The initialization code is as follows
    Bapi_Po_Create1_Input input = new Bapi_Po_Create1_Input();
    input.setPoheader(new Bapimepoheader());
    input.setPoheaderx(new Bapimepoheaderx());
    input.addPoitem(new Bapimepoitem());
    input.addPoitemx(new Bapimepoitemx());
    input.addPoaccount(new Bapimepoaccount());
    input.addPoaccountx(new Bapimepoaccountx());
    input.addPoschedule(new Bapimeposchedule());
    input.addPoschedulex(new Bapimeposchedulx());
    input.addPotextheader(new Bapimepotextheader());
    Thanks
    Sriram

  • BAPI 001 No instance of object type PurchaseOrder has been created. Externa

    HI,
    we have the below mentioned issue when we are creating SC through describe requirement.
    BAPI 001 No instance of object type PurchaseOrder has been created. External reference:  (Document Number XXXXXXXXXXX
    06 213 Error in net price calculation, item 000010 (Please correct)  (Document Number XXXXXXXXXXX)
    we are trying to assign the inforrecord when we are creating the SC through describe requirement.
    Could any one suggest what is going wrong
    regards
    subbu

    this error is misleading error message from SRM SIDE . click follow on document icon via monitor sc. you will get real error message in application monitor or rz20.
    check the real error message in rz20.
    update here what is ther error message...
    muthu

  • It is showing as error *Instance of object type PO could not be changed*

    HI Gurus,,
    i have requirement in PO Change IDOC , i have tested this IDOC .. but it is showing in Status record as error Document is does not exist
    and in Segmentheader for E1BPMEPOHEADER ..it is showing as error Instance of object type PO could not be changed
    SEGMENT NAME : E1BPMEPOHEADER
      PO_NUMBER
      COMP_CODE
      DOC_TYPE
      CREAT_DATE
      VENDOR
      PURCH_ORG
      PUR_GROUP ;;;
    we have entered related entries in it ...
    am uanble to find out where is porblem lies in it... plz help ASAP ...
    Thanks in advance..

    HI srinivas
    "It seems a data issue, Similar PO might be changed already and thus in SAP it is not allowing to change.
    So try changing the test data and post the IDOC again , it will change the PO . "
    yes we have entered the PO create and PO change .. where in PO change we have changed only QUANTITY and DATE .
    and showing this error" *It is showing as error Instance of object type PO could not be changed. "*
    Thanks in advance.

  • The difference between class, instances and object?

    I've been reading a JAVA book and i've come accross terms such as class, instances and object. What I don't understand is why after creating a class, we have to create an object and then create instances? What's an object and instance anyway? I don't really understand the term. Can anyone pls help and explain it to me in an easier way to understand?
    Thanks a lot.

    A Class defines what attributes (properties) and methods a particular item will have.
    Ex. You have a class person
    public class Person
    public void walk()
    String name;
    int age;
    }An instance and Object are the same. When you create an instance of a class, you get an object of that class.
    Person kevonline = new Person();You can then set kev's name, age, make him walk, etc... since these are defined in the class Person.
    HTH,
    Dewang

  • Multiple instances of objects

    Ok, so I am making an RPG kind of like Dungeons and Dragons. Unfortuantely with that comes the need for multiple, different objects of the same class: Monster
    import java.util.*;
    public class BattleCall
         public static void main(String[] args)
              State h = new State();
              final Monster Goblin = new Monster(12,10,12,1,8,-1,13,1,8,2,"Goblin");
              final Monster Pirate = new Monster(14,10,14,2,9,-1,12,1,10,4,"Pirate");
              h.h(Goblin,Pirate);
              This calls two instances of the monster class. Because of sheer frustration I have gotten rid of the whole battle scheme for now. All I am trying to do right, through the State class is show the AC's of the two monsters (the first parameter)
    Here is my monster class
    //Beginning stuff here, too lazy to retype, no method
    int AC;
    //All other variables here, AC is the first one
    Monster(int AC1)//All other variables also in here, program on laptop not desktop, too lazy to retype
    AC = AC1;
    }Mind my laziness, it's late and I'm just about to go to bed.
    Anyways, through the tow instances I need to keep the variables seperate, here is the code for the State class
    //beginning stuff here
    public void h(Monster mon1,Monster mon2)
    System.out.println(mon1.AC+","+mon2.AC);
    //end stuffOk so you have all my code, now for the output...... 14,14 it should be 12,14 (12 being goblin, 14 being pirate) If I run my battle with two enemies, it places the pirate in twice, it's name, intelligence, strength, everything instead of pirate once goblin once..... I have tried using arrays to achieve this but to no avail... If this is possible PLEASE help me out.

    ok, and can you please tell me how it doesn't follow those guidelines? If he where to make it shorter then it wouldn't be self contained. He showed us just the methods that where causing the problem. How would you present the problem "Hlpes prgrm no wrk!!!!!" and leave it at that? I'll just point this out before you say anything else:
    U nEd 2 b clearer bout wot d prob iz!_
    Fact is your not helping him at all.
    Now on to his question. I have run code similar to yours in my own sessions and everything turns works out fine.
    public class Monster{
         public int AC;
         public Monster(int a){
              AC = a;
    public class State{
         public State(){}
         public void h(Monster mon1, Monster mon2){
              System.out.println(mon1.AC+","+mon2.AC);
    public class Test{
         public static void main(String[] args){
              State h = new State();
              final Monster Goblin = new Monster(12);
              final Monster Pirate = new Monster(14);
              h.h(Goblin, Pirate);
    }That outputs "12,14". So the problem most be somewhere else in the code.

  • Object Reference not set to instance of Object when sub-report on new page

    I have a problem when my sub-report goes onto the second page of the report, with an error message.
    My VB.NET displays a report and sub-report (in the footer) in a CrystalReportViewer:
    - When both are on the first page, both display fine
    - When the sub-report (or at least part) goes to the second page, the report displays OK, but without the subreport. When I go to page 2 of the report - hoping to see the sub-report - an error message is displayed, with title "Crystal Report Windows Forms Viewer" and text "Object Reference not set to an instance of an object".
    This problem occurs both on my development machine in VS and at a user site.
    Am desperate for some ideas please! I have VB.NET in Visual Studio 2010, and SAP Crystal Reports, version for Visual Studio 2010. The program is targeted for .NET Framework 3.5.
    I looked for the HandleException event on my Windows Forms Viewer, as suggested by SAP and Microsoft, but cannot find this. See for [example|http://devlibrary.businessobjects.com/businessobjectsxi/en/en/crystalreports_dotnet_sdk/crystalreports_net_doc/doc/crsdk_net_doc/html/crlrfwindowsformscrystalreportviewerclasshandleexceptioneventtopic.htm]

    Usually, the error is due to the object going out of scope. Placing the object in a session may help. Moving the CR code to page init or page load may help. Looking at samples may help:
    http://wiki.sdn.sap.com/wiki/x/JQBmBQ
    CR Dev help files are here:
    SAP Crystal Reports .NET API Guide     http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/crnet_api_2010_en.zip
    SAP Crystal Reports .NET SDK Developer Guide     http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/crnet_dg_2010_en.zip
    Finally, ensure you are using Service Pack 2 (see the sticky thread at the top of this forum).
    Ludek
    Follow us on Twitter http://twitter.com/SAPCRNetSup
    Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

Maybe you are looking for

  • Upgrade from R/3 4.6C to ECC 6.00 : languages

    Hi, We're trying to upgrade from SAP R/3 4.6C to ECC 6.00 under NT environment, having Oracle as database. During the preparation phase, we got the following error, and in our current SAP system R/3 we have 2 additional languages NL and FR (EN and DE

  • File extensions not working as expected, is this normal?

    In the finder, there is an option to "Show all file extensions". So normally, a certain image file could be either "image" or "image.jpeg". However, I have some weird files: "image.jpeg.jpeg" EVEN WHEN I HAVE SET THE EXTENSIONS TO BE HIDDEN. What I w

  • [Logical Standby] Which table/SQL caused paging-out

    We have a Primary-Logical DR configuration. Recently, it has a problem with the logical: it's continuously paging out data from some transactions: SELECT SUBSTR(name, 1, 40) AS NAME, SUBSTR(value,1,32) AS VALUE FROM GV$LOGSTDBY_STATS; number of prepa

  • Need a FM for change delivery quantity

    Hello, I need a FM to update delivery quantity, I have look for the BAPI BAPI_OUTB_DELIVERY_CONFIRM_DEC but I didn't find how it works. Any help are welcome Frédéric

  • RFC receiver adapter not getting timed out

    Hello Everyone, I have a scenario like this: Web-Service --> PI -->RFC (using receiver RFC channel)-->Response back to PI from RFC --> response back to Web-Service This RFC is taking more than 5 minutes to give response back to PI but still I am not