Vector loosing values of object?

Hello, hope someone can help me out a bit on this issue that i'm encountering
in the following code am reading pixel values from a raster (image) and storing the relevant ones in a Vector, however am encountering a problem in the last "if statement" as the vector is not storing the right values that are printed on screen but rather storing the values set by: currentPixel.setBlank();
i cannot determine the reason for this behaviour since the "currentPixel" object is stored before the currentPixel.setBlank() method. Also what is puzzling me more is that the values in the println command are being displayed correctly! however when i dump all the values of the vector on screen the values are those assigned by currentPixel.setBlank() method;
for (int h=0;h<height;h++){
            for (int w=0;w<width;w++){
                position = (h*width)+w;
                previousPixel = new PixelHolder();
                previousPixel = currentPixel;
                currentPixel = new PixelHolder();
                currentPixel.setValue(pixelStore[position]);
                currentPixel.setX(w);
                currentPixel.setY(h);
                previous = previousPixel.value;
                current = currentPixel.value;
                if (previous > current){
                    System.out.println(" pixel:"+ previousPixel.positionX+","+previousPixel.positionY+","+ previousPixel.value );
                    //store previousPixel;
                    myPixelVector.addElement(previousPixel);
                } else if (current > previous){
                    bufferPixel = new PixelHolder();
                    bufferPixel = previousPixel;
                    buffer = bufferPixel.value;
                if ((w == width-1) && (current > buffer)){
                    //store currentPixel;
                    System.out.println("3rd phase currentpixel:"+ currentPixel.positionX+","+currentPixel.positionY+","+ currentPixel.value );
                    myPixelVector.add(currentPixel);  //problems here..
                    bufferPixel.setBlank();
                    currentPixel.setBlank();
setBlank method from PixelHolder();:
public void setBlank(){
    positionX = 0;
    positionY = 0;
    value = 0;
}output by : System.out.println("3rd phase currentpixel:"+ currentPixel.positionX+","+currentPixel.positionY+","+ currentPixel.value );:
previous pixel:178,63,106
3rd phase currentpixel:179,63,105
output by displaying contents of myPixelVector on screen (note the last three values tally in the first line, whereas in second line these are as per the setBlank method):
i: 3289,178,63,106
i: 3290,0,0,0
hope any one can brighten my thoughts up as i am really lost with this one!
thanks a lot!
S

the problem is that when you are adding currentPixel to the Vector, you are adding the instance being pointed to by currentPixel, which retains the pointer. Thus when you setBlank currentPixel, you are blanking the instance which is also being referenced in the Vector.
A way around it is to add a clone of the pixel to the Vector - make sure the clone method is implemented in that class.
E.g. myPixelVector.add(currentPixel.clone());
Hope this Helps!
Jon

Similar Messages

  • Vector takes only takes Objects to add to it.

    my question is that vector class add only object then in the following program i add constant int value to it it gives output as i given below the program.then how it can happened? plz tell
    import java.awt.*;
    import java.util.*;
    public class Vec{
    public static void main(String argv[]){
    Vec v = new Vec();
    v.amethod();
    }//End of main
    public void amethod(){
    Vector mv = new Vector();
              int a=10;
    //Note how a vector can store objects
    //of different types
    mv.addElement("Hello");
    mv.addElement(Color.red);
    mv.addElement(new Integer(99));
    mv.addElement(99);
              mv.addElement(a);
    //Walk through each element of the vector
    for(int i=0; i< mv.size(); i++){
    System.out.println(mv.elementAt(i));
    }//End of amethod
    After compile :
    Note: Vec.java uses uncheked or unsafe operations
    Note: Recompile with -Xlint:unchecked for details
    After Run :     Hello
                   java.awt.Color[r=255,g=0;b=0]
                   99
                   99
                   10

    because of a new feature in java 1.5 called autoboxing which automatically converts between primitive types and their wrapper types as needed. also, since you're using java 1.5 now, it's no longer true that Vectors can only have Objects added to them. read about generics, too

  • Vector can't give objects

    I have a program using a vector, I store BufferedImage objects in it. But when I try to access them later the compiler won't let me because the method in Vector defines that Object is the type of object being passed, and cannot convert it to a BufferedImage.
    I tried using an Object to store it which worked, but when I tried to use it to draw, it wasn't recognised as an Image, being an Object and still wouldn't compile.
    Is this because I have jdk 1.3? Is there anotherway Should I be using a vector? Should I edit Vector to pass BufferedImages rather than Objects?
    I am storing frames like this:
    Vector.addElement(java.awt.Robot.createScreenCapture(Rectangle)));
    and retrieving them like this:
    Graphics.drawImage(Vector.elementAt(index),0,0,this);
    The syntax is correct but Object is not compatible with BufferedImage!
    There must be another way...
    Rufus,

    Thanks for that. I thought you could only cast types
    and not Objects.The correct way to express that would be to say: I thought you could only cast primitive types and not class types. But you can cast both primitives and classes, even though the casting behaves a little differently.
    One additional complication is that Object (with a capital O) isn't an object but a class. All classes extend Object by default. That's why collections like Vector can store objects of any class.

  • Passing Values to Object Type Attributes

    Hi Experts,
    I need to pass values to object type attributes amount,channel and company code from zprogram.
    I have got FM 'SWO_INVOKE'.But in this FM how will I pass values to 3 attributes.
    I have created object type through SWO1 .Is it necessary to call FM SWO_CREATE before FM 'SWO_INVOKE'.
    Please suggest.
    Regards,
    Kaustubh.

    Hi,
    I guess you will have to Initialize business object first by using the function module "SWO_CREATE' and then call the other function module to pass the attributes. I am not sure, but please check by passing the attribute name and value to the tables parameter 'CONTAINER'.
    CONTAINER-ELEMENT = <Attribute name>.
    CONTAINER-VALUE = <value from the Zprogram>.
    Hope this will help.
    Thanks,
    Samson

  • What is the use of setting null values to Objects?

    What is the use of setting null values to Objects?
    regards,
    namanc

    It's more of a safety trap within java to handle the "programmers are still humans" exception.
    String myname;
    // print what???? Forgot to initialize the name!
    System.out.println(myname);Java will complain about myname not being initialized. It won't when you do this:
    String myname = null;
    // allright, your name is null
    System.out.println(myname);In the second case you are showing to java that you know what you are doing.

  • Loosing references to objects

    I am accessing Lite using Java using the JAC API's: POLConnection, POLClass etc.
    The program is temporarily and eratically loosing references to objects and then find them again.
    The program logs on and looks up the objects it needs, checking the refernces have been found and are not null. A button initiates a query to uses these objects to retrieve data. It eratically raise a null pointer exception, the connection or class reference is null. By pressing the button again the query works ok, even though the connection and class objects have not been reset, they are suddenly no longer null.
    Help.

    May I be so bold to make a suggestion here?
    In future questions like this should be posted in a more appropriate forum. Like here http://forum.java.sun.com/forum.jspa?forumID=37
    This could be of more help to you because there are in fact users like this guy http://forum.java.sun.com/profile.jspa?userID=658641 who actually work for Sun on the VM and answer questions in there.
    So you could get a real answer rather than a bunch of guessing or idiotic contributions from Questie and the like.

  • Activity values of object K_KA_RPT

    Hi all,
    I'm working on authorization for t-code KE80. I'v found suspicious activity values of object K_KA_RPT as following:
    L0     All functions
    L1     Function range level 1
    L2     Function range level 2
    Would you please explain me about these values? I don't really understand about them.
    Thanks you all in advance.
    Peerasit

    Hi,
      The reason is, that if you have restrictions via particular activities for the object K_KA_RPT (you do not have "*", but "04", "16", "32", etc.), the activities L0, L1, L2 are checked as well. If you do not have any of the L0 - L2 maintained for the K_KA_RPT, the most restricted is taken into account, which leads to restricted menu in the executed report.
    If a user doesn't have authority 'L0' and he execute a drilldown report with the output type 'Classic drilldown report', not all functionalities will be available in the executed report.
    But the user can navigate via menue: > Extras > More functions > Level 2 in order to get more functions (e.g. Export) - if the user has authority 'L2'.
    If the user execute a drilldown report with the output type 'Graphical report-output', authority 'L2' is checked.
    If the user hasn't authority 'L2' all functions are displayed in the menue, but e.g. 'Export' is greyed out (inactive).
    So, if you want to give the authority to export a report to an user, you have, you have to give him authority 'L2'.
    You find a documentation in the 'SAP Library' under:
    > Cross-Application Components > CA - Drilldown Reporting > Executing   a Report: - Function Levels for Different Users.
    regards
    Waman

  • Lookup query to get Manager ID value on object form

    Hi ,
    I have created a Manager ID field on object form which is of type lookup field.
    Can any one please tell me that how can i write Lookup query to get Manager ID value on object form.
    Thanks in Advance

    I was looking for something like this today too.
    Here's what I came up with:
    SELECT fu.user_id, fu.employee_id, fu.user_guid, pe1.full_name, pe2.full_name SUPERVISOR, pe2.employee_id
    FROM fnd_user fu
    JOIN per_employees_x pe1 on pe1.employee_id = fu.employee_id
    JOIN per_employees_x pe2 on pe2.employee_id = pe1.supervisor_id
    WHERE fu.user_id = $(user_id)
    Edited by: user12232265 on Feb 24, 2010 3:20 PM

  • For Grant nnnnnn, specify a value for object FUND error -Urgent

    I work in SRM area and my knowledge of Grants management is almost nil. We have a PO in SRM which has account assignment associated with a Workorder and Fund. When we look at the Grant it has all green lights and is confirmed by our FI/CO team everything is correct. But since R/3 is giving this message "For Grant nnnnnn, specify a value for object FUND" , I am sure there is something missing somewhere. Some additional information, the PO is from last fiscal year but it was changed for account assignment this fiscal year. But we checked the Fund itself is valid for some more time to come.
    Any ideas on which transaction codes to see, what to look at etc. will be appreciated.
    Thanks

    Hi Manjula,
    You have been facing this issue becuase the sequence of the fields while mapping them is not perfect, hence the 0date field is capturing some other data rather than picking the exact date value.
    Check the order of fields and match it with the file (if you are loading data from a flat file)
    Also, have a look at the weblog which talks about general mistakes in loading from file.
    /people/sergio.locatelli2/blog/2006/11/02/upload-file-in-bw-common-mistakes-and-hints-to-take-in-mind
    Cheers!
    Amit

  • Please help with retrieving values from object stored in a vector

    hi..
    i have a class Magazine with 2 varibles name and price like this
    class magazine
    String name;
    int price;
    i have created a vector called selectedmag which stores objects of Magazine class... now each object will contain the name and price rite...
    i want to print the values stored in vector ie i want to print the vector elements...like
    Name: Mag1
    Price: 10
    which wil be present in object1...
    and then
    Name: Mag2
    Price:15
    which wil be present in object2...
    and so on...
    plz help...
    if i give selectedmag.elementAt(position) i am not able to get the above output...plz help me.....
    thanks,
    Akshatha

    hi,
    Yes i have used a for loop to print the values... it goes like this
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    class Magazine
         String title;
         int price;
    public class sessiontrack1 extends HttpServlet
         public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
              res.setContentType("text/html");
              PrintWriter out=res.getWriter();
              HttpSession session=req.getSession(true);
    // This is my vector          
    Vector myshoppingcart=(Vector)session.getAttribute("ShoppingCart");
              if(myshoppingcart==null)
                   myshoppingcart=new Vector();
              Magazine selectedMag=new Magazine();
              selectedMag.title=req.getParameter("Title");
              selectedMag.price=Integer.parseInt(req.getParameter("Price"));
    //Putting Magazine object into the vector myshoppingcart
              myshoppingcart.addElement(selectedMag);
              session.setAttribute("ShoppingCart",myshoppingcart);
              out.println("<html><body>U have selected these magazines");
              out.println("<br>");
         //Enumeration vEnum=myshoppincart.elements();
    //here a am trying to print output the values
              for(int i=0;i<myshoppingcart.size();i++)
    out.println("Name:" + (Magazine)myshoppingcart.elementAt(i));
                   out.println("<br>");
    out.println("Price:" + (Magazine)myshoppingcart.elementAt(i));
                   out.println("<br>");
              out.println("</body></html>");
    this is a servlet program.... plz suggest me how to print the values... in the following format
    Name: Book1
    price: Rs 10
    Name:Book2
    price:Rs 15
    Akshatha

  • Vectors: contains() inconsistency with Object equals()

    Hi,
    I have a problem with using Vector contains() on my own classes.
    I have a class TermDetails, on which I have overloaded the equals() method:
         public boolean equals(Object other) {
              try {
                   TermDetails otherTerm = (TermDetails) other;
                   return (term.equals(otherTerm.term));
              catch (Exception e) {
                   try {
                        String otherTermString = (String) other;
                        return (term.equals(otherTermString));
                   catch (Exception f) {
                        System.out.println("Can't convert Object to TermDetails or String");
                        System.out.println(f.getMessage());
                        return(false);
         public boolean equals(String otherTermString) {
              return(term.equals(otherTermString));
    The Vector.contains() should then use one of these equals methods to return correctly, but doesn't use either of them... any ideas why not?
    (I've tried adding some console output in the equals methods, just to prove if they get called or not. They don't.)
    Thanks in advance!
    Ed

    This won't work. It only tests whether the two objects are of the same class. In general, you need to test a number of things:
    1) if obj == this, return true
    2) if obj == null, return false
    3) if obj.getClass() != this.getClass() return false
    (Note: You don't need getClass().getName(). Also, there are times when the classes don't have to match, but it's sufficient that obj and this implement a particular interface--Map for instance).
    4) if all relevant corresponding fields of obj and this are equal, return true, else false.
    That's just a high level run-down, and you should definitely look at the book that schapel mentioned.
    Also, this probably won't affect Vector.contains, but make sure that when you override equals, you also override hashCode. The rule is that if a.equals(b) returns true, then a.hashCode() must return the same value as b.hashCode(). Basically any field that is used in computing hashCode must also be used in equals.
    Note that the converse is not true. That is two objects with the same hashCode don't have to be equal.
    For instance, if you've got a class that represents contact info, the hashCode could use only the phoneNumber field. hashCode will then be fast to compute, will probably have a good distribution (some distinct people's contact info could have the same phone number, but there won't be a large overlap), and then you use phone number plus the rest of the fields (address, etc.) for equals.
    Here's an example that shows that equals will work if
    written correctly
    import java.util.Vector;
    public class testEquals {
    public static void main(String args[]) {
    Vector testVector = new Vector();
    testVector.add(new A());
    testVector.add(new B());
    System.out.println("A == A? " +
    + testVector.contains(new A()));
    System.out.println("B == B? " +
    + testVector.contains(new B()));
    class A {
    public boolean equals(Object object) {
    if (getClass().getName() ==
    = object.getClass().getName()) {
    System.out.println("A == A");
    return true;
    } else {
    return false;
    class B {
    public boolean equals(Object object) {
    if (getClass().getName() ==
    = object.getClass().getName()) {
    System.out.println("B == B");
    return true;
    } else {
    return false;

  • Hashtable values taking object.

    hi,
    i have a hashtable hashAllDetails(keys, objUserDEtails)
    here i have put in the values of the keys through various arrays and my values take are objects of a class UserDetails which have the following variables CountBasic, CountAdvanced variables etc.
    now i need to extract information per key about the CountBasic and CountAdvanced variables.
    how do i do this??
    i extracted the keys thru the following code. its working fine how do i go ahead???
    Enumeration enumObj = hashAllDetails.keys();
    Vector vecKeys=new Vector();
    while(enumObj.hasMoreElements())
        String strElem=(String)enumObj.nextElement();
         vecKeys.add(strElem)
    }                                //End while
    for(int i=0; i<vecKeys.size(); i++)
         System.out.print((String)vecKeys.get(i) + ":     ");
    }  

    How about using Hashtable.get(Object key) ?
    BTW, why are you filling a Vector with keys instead of directly using keys Enumeration?
    Note that if you want to get all key,value pairs from your Hashtable, you might use Hashtable.entrySet() to get all entries, and iterate through them.for(Iterator it = hashAllDetails.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry entry = (Map.Entry)it.next();
        String key = (String)entry.getKey();
        UserDetails value = (UserDetails)entry.getValue();
        // Do what you want with key and value
    }

  • Data mart from two DSOs to one - Loosing values - Design issue

    Dear BW experts,
    I´m dealing with a design issue for which I would really appreciate any help and suggestions.
    I will be as briefly as possible, and explain further based on the doubts , questions I received in order to make it easier go through this problem.
    I have two standard DSOs (DSO #1 and #2) feeding a third DSO (DSO #3), also standard.
    Each transformation DOES NOT include all fields, but only some of them.
    One of the source DSO (let´s call it DSO #1) is uploaded with a datasource that allows reverse type of records  (Record Mode = 'R'). Therefore some updates on DSO #1 comes with one entry with record mode 'R' and a 2nd entry with record mode = 'N' (new).
    Both feeds are delta mode, and not the same entries are updated through each of them, but the entries that are updated can differ (means an specific entry (unique key values)  could be update by one of the feeds, but no updates on the 2nd feed for that entry).
    Issue we have:  When a 'R' and 'N' entries happen in DSO #1 for any entry, that entry is also reversed and re created in the target DSO #3 (even being that not ALL fields are mapped in the transformation), and thefore we loose ALL the values that are exclusively updated through DSO #2, becoming blank.
    I don´t know it we are missing something in our design, or how should we fix this issue we have.
    Hope I was more or less clear with the description.
    ´d really appreciatted your feedback.
    Thanks!!
    Gustavo

    Hi Gustavo
    Two things I need to know.
    1. Do you have any End Routine in your DSO? If yes, what is the setting under "Update behavior of End Routine Display"....Option available right side of Delete Button ater End Rouine.
    2. Did you try with Full Load from DSO1 and DSO2 to DSO3? Do you face the same problem?
    Regards
    Anindya

  • How to get the values from object ?

    hi everybody,
    i am experimenting with oops concept. first have a look at these coding and then tell me this.
    what do i have to do to get the value of an object created. i want to use the get method to get the name, food and quantity, without the use of the created object. i mean i want to make the process independent of how many objects i make so that i can find a value given the name of a person in the object.
    when this is done, i want to use this to create filed of a specific doc format for each object created. now when we are using the get method i want to read whats on the object value .
    Am i being clear or are thing very confusing, please let me know wht u think so i can clarify myself more.
    public class obj {
         String name;
         String food;
         int quantity;
         public void set(String ndata, String fdata,int qdata )
              this.name=ndata;
              this.food=fdata;
              this.quantity=qdata;
         public  void get()
              System.out.println( this.name+"  "+this.food+"  "+this.quantity);
         public static void main(String[] args) {
              obj obj1= new obj();
              obj1.set("varun", "burger", 2);
              obj obj2= new obj();
              obj1.set("roshan", "diet pepsi", 1);
              obj obj3= new obj();
              obj1.set("aman", "biryani", 2);
              obj2.get();
    }

    cyberpanther wrote:
    hi everybody,
    i am experimenting with oops concept. first have a look at these coding and then tell me this.
    what do i have to do to get the value of an object created. i want to use the get method to get the name, food and quantity, without the use of the created object. no. wrong.
    i mean i want to make the process independent of how many objects i make so that i can find a value given the name of a person in the object.no. sounds more like you're experimenting with drugs.
    when this is done, i want to use this to create filed of a specific doc format for each object created. now when we are using the get method i want to read whats on the object value .
    Am i being clear or are thing very confusing, please let me know wht u think so i can clarify myself more.you're clearly confused.
    public class obj {
         String name;
         String food;
         int quantity;
         public void set(String ndata, String fdata,int qdata )
              this.name=ndata;
              this.food=fdata;
              this.quantity=qdata;
         public  void get()
              System.out.println( this.name+"  "+this.food+"  "+this.quantity);
         public static void main(String[] args) {
              obj obj1= new obj();
              obj1.set("varun", "burger", 2);
              obj obj2= new obj();
              obj1.set("roshan", "diet pepsi", 1);
              obj obj3= new obj();
              obj1.set("aman", "biryani", 2);
              obj2.get();
    }utterly awful code. this is how it should not be done.
    %

  • Problem with value in object element declared as NUMBER(26,3)

    We have an object OBJ_NAME_1 created like below and total element in the object are around 100 with in which only one element is of data type VARCHAR2(4000). Other are with small size as below
    create or replace TYPE OBJ_NAME_1 AS OBJECT
    ( v_col1 VARCHAR2(4),
    v_col2 VARCHAR2(4),
    d_date DATE,
    amount_1 NUMBER(26,3) . . . . . . . . . . .)
    And we are creating an VARRY of above object as below:
    create or replace TYPE ARRAY_NAME_1 AS VARRAY(1000) OF OBJ_NAME_1
    Now we have one procedure with IN parameter of type ARRAY_NAME_1 as below and we are calling this procedure from java.
    create or replace PROCEDURE SP_PROC_1 (
    P_ARR_1 IN ARRAY_NAME_1,
    P_FILE IN VARCHAR2,
    E_MESS OUT VARCHAR2,
    E_CODE OUT NUMBER) . . . . . . . .
    My problem is with value of element amount_1 of array ARRAY_NAME_1 in the procedure. Actually data type of this element is NUMBER(26,3) in object. But from java we are able to pass value like 1234.12345 (with 5 decimal).
    The declare section of the procedure are like below :
    l_OBJ_NAME_1 OBJ_NAME_1;
    m_amount_1     table_1.amount_1%type; /* amount_1 in table_1 declared as NUMBER(26,3)*/
    n_amount_1     NUMBER(26,3);
    In the begin section we are assigning variable like below:
    IF (P_ARR_1 .COUNT>0) THEN
    FOR i IN P_ARR_1.FIRST .. P_ARR_1.LAST LOOP
    l_OBJ_NAME_1 := P_ARR_1(i);
    m_amount_1 := P_ARR_1(i).amount_1;
    n_amount_1 := P_ARR_1(i).amount_1;
    END LOOP;
    The value of variables are below after above assignment:
    l_OBJ_NAME_1 . Amount_1 → 234.12345 (without round off)
    m_amount_1 → 234.12345 (without round off)
    n_amount_1 → 234.123 (with round off)
    Actually all the above 3 variable/element has been declared as NUMBER(26,3), then the value in these variables should be with rounded up to 3 decimal place. Then why it is not happening with variable
    l_OBJ_NAME_1 . Amount_1 and m_amount_1?
    Please help.
    Edited by: SANT007 on Aug 12, 2011 9:45 AM

    Okay, thanks Patrick. I commented that out so now I can see the full error message. Actually, now the page just returns an "OK" (nothing else), and I click on that to return back to the page where I see:
    Checksum error for Hidden and Protected item ID (26968176992578859), value ([object]), posted checksum (326873D5A54A4AF425EC4D500B9B4D02), expected checksum (********************************), index_i (10), index_j (2), index_m (2);
    Okay, so that's evidently a new option in 3.1, it should have just been a 'Hidden' item, not 'Hidden and Protected'. So, I change this back to just 'Hidden', refressh the page, the re-execute it and try to select from the popup again. This time, instead of the more-or-less blank page with only "OK" on it, I also get "ORA-01722: invalid number" above the "OK". When I click the "OK", then I am returned back to the last good 'runnable' page I executed (since the search page is no longer 'runnable' (the javascript evidently is still returning an object instead of a number).
    On a previous run of trying to track the problem down, I made the :P3_SEQ as a regular text field so I could try to see what was going on, and it briefly displayed "[object]" before the search executed and returned the error.
    So thanks for helping me get past the first stage so I could see a better version of what the error is. Now I just need to figure out why an object is being returned instead of number. This worked fine in 3.0, and the only thing I can think of is that something, somewhere in 3.1's javascript is slightly different now, but I really don't know.
    Bill Ferguson

Maybe you are looking for