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.

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

  • How can we give F4 help

    Dear Freinds,
                     I would like to know can we give F4 help to employee no , similar to the one which has
    the F4 help when we have user logical database PNP . I mean to say can i give the F4 help to the field emp_no( Employee no) like the same functional which we get for the field Personnel no ( pernr-pernr) when we are using the logical database PNP.
    In my report iam not using the logical databse (PNP)in this requirement. If i can provide the F4 help on my field  emp_no  , please help me in this regard.
    Thanks & regards
    Divya.

    Creating a basic search help which allows you to provide the user with a selection help to select specific fields from
    a table or view is very straight forward. Simply create a search help with the desired table as the selection method
    and add the fields you want them to see/select into the search help parameters section. See below for details of how
    to create a search help for table TRDIR
    Step1: Execute transaction SE11
    Step2: Create new search help called 'ZSH' (must be less than 5 chars long to be used as matchcode)
    Step3: Enter the following details:
    Step4: Save and activate
    Step5: Add following line into your program: PARAMETER p_prog LIKE trdir-name MATCHCODE
    OBJECT zsh.
               Or see other methods of adding a search help.

  • How can I give a name to excel sheet and open another one?

    Hello!
    I use CSVWriter for writing in excel file.
    I have 2 questions:
    1.     How can I give a name to a Sheet in excel file?
    2.     How can I save the first Sheet and open another one with a different name?
    Thanks!

    This is the equivalent in Apache POI which may or may not help. I've never used CSVWriter.
    HSSFSheet sheet1 = workbook.createSheet("sheet1Name");
    HSSFSheet sheet2 = workbook.createSheet("sheet2Name");Then you can use either sheet object to write your contents. Look at the documentation for CSVWriter that pertains to sheets as it should tell you how.

  • Can we give more than one value for an Authorization field in Auth-Check.

    Hi all,
    Can we give more than one value for an Authorization field in Auth-Check.
    Ex: AUTHORITY-CHECK OBJECT 'S_TRVL_BKS'
    ID 'ACTVT' FIELD '02'
    ID 'CUSTTYPE' FIELD <Value 1> <Value 2> <Value 3>.
    IF SY-SUBRC 0.
    MESSAGE E...
    ENDIF.
    If yes, please help me with exact syntax.
    Think it will be like
    ID 'CUSTTYPE' FIELD: <Value 1>, <Value 2>, <Value 3>.

    Hi,
    yes we can give more than one field.
    program an AUTHORITY-CHECK.
    AUTHORITY-CHECK OBJECT <authorization object> 
       ID <authority field 1> FIELD <field value 1>. 
       ID <authority field 2> FIELD <field value 2>. 
       ID <authority-field n> FIELD <field value n>. 
    The OBJECT parameter specifies the authorization object.
    The ID parameter specifies an authorization field (in the authorization object).
    The FIELD parameter specifies a value for the authorization field.
    The authorization object and its fields have to be suitable for the transaction. In most cases you will be able to use the existing authorization objects to protect your data. But new developments may require that you define new authorization objects and fields.
    please reward points, if it is useful.
    satish.

  • Can anyone give me some documents for data cluster

    Hi,
    can anyone give me some documents for data cluster?
    ths!
    regards!

    Hi ,
    The following is a documentation on the <b>Data Cluster</b>:
    <b>Data clusters</b> are specific to ABAP. Although it is possible to read a cluster database using SQL statements, only ABAP can interpret the structure of the data cluster.
    You can store <b>data clusters</b> in special databases in the ABAP Dictionary. These are called ABAP cluster databases, and have a prescribed structure:
    <u><b>Cluster Databases</b></u> ( I have explained the cluster databse below )
    This method allows you to store complex data objects with deep structures in a single step, without having to adjust them to conform to the flat structure of a relational database. Your data objects are then available systemwide to every user. To read these objects from the database successfully, you must know their data types.
    You can use cluster databases to store the results of analyses of data from the relational database. For example, if you want to create a list of your customers with the highest revenue, or an address list from the personnel data of all of your branches, you can write ABAP programs to generate the list and store it as a data cluster. To update the <b>data cluster</b>, you can schedule the program to run periodically as a background job. You can then write other programs that read from the data cluster and work with the results. This method can considerable reduce the response time of your system, since it means that you do not have to access the distributed data in the relational database tables each time you want to look at your list.
    <b>Cluster Database :</b>
                    Cluster databases are special relational databases in the ABAP Dictionary that you can use to store data clusters. Their line structure is divided into a standard section, containing several fields, and one large field for the <b>data cluster.</b>
    <b>Creating a Directory of a Data Cluster</b>
    To create a directory of a data cluster from an ABAP cluster database, use the following statement:
    Syntax
    <b>IMPORT DIRECTORY INTO <dirtab>
                     FROM DATABASE <dbtab>(<ar>)
                     [CLIENT <cli>] ID <key>.</b>
    This creates a directory of the data objects belonging to a data cluster in the database <dbtab> in the internal table <dirtab>. You must declare <dbtab> using a TABLES statement.
    To save a <b>data cluster</b> in a database, use the <b>EXPORT TO DATABASE</b> statement .
    For <ar>, enter the two-character area ID for the cluster in the database. The name <key> identifies the data in the database. Its maximum length depends on the length of the name field in <dbtab>. The CLIENT <cli> option allows you to disable the automatic client handling of a client-specific cluster database, and specify the client yourself. The addition must always come directly after the name of the database.
    The IMPORT statement also reads the contents of the user fields from the database table.
    If the system is able to create a directory, SY-SUBRC is set to 0, otherwise to 4.
    The <b>internal table</b> <dirtab> must have the ABAP Dictionary structure CDIR.
    <b>******** Sample Program illustrating the data cluster .</b>
    PROGRAM Zdata_cluster.
    TABLES INDX.
    ******to save data objects in cluster databases
    DATA: BEGIN OF ITAB OCCURS 100,
            COL1 TYPE I,
            COL2 TYPE I,
          END OF ITAB.
    DO 3000 TIMES.
      ITAB-COL1 = SY-INDEX.
      ITAB-COL2 = SY-INDEX ** 2.
      APPEND ITAB.
    ENDDO.
    INDX-AEDAT = SY-DATUM.
    INDX-USERA = SY-UNAME.
    INDX-PGMID = SY-REPID.
    EXPORT ITAB TO DATABASE INDX(HK) ID 'Table'.
    WRITE: '    SRTF2',
         AT 20 'AEDAT',
         AT 35 'USERA',
         AT 50 'PGMID'.
    ULINE.
    SELECT * FROM INDX WHERE RELID = 'HK'
                       AND   SRTFD = 'Table'.
      WRITE: / INDX-SRTF2 UNDER 'SRTF2',
               INDX-AEDAT UNDER 'AEDAT',
               INDX-USERA UNDER 'USERA',
               INDX-PGMID UNDER 'PGMID'.
    ENDSELECT.
    ****To create a directory of a data cluster from an ABAP ****cluster database
    DATA DIRTAB LIKE CDIR OCCURS 10 WITH HEADER LINE.
    IMPORT DIRECTORY INTO DIRTAB FROM DATABASE
                                      INDX(HK) ID 'Table'.
    IF SY-SUBRC = 0.
      WRITE: / 'AEDAT:', INDX-AEDAT,
             / 'USERA:', INDX-USERA,
             / 'PGMID:', INDX-PGMID.
      WRITE  / 'Directory:'.
      LOOP AT DIRTAB.
        WRITE: / DIRTAB-NAME,  DIRTAB-OTYPE, DIRTAB-FTYPE,
                 DIRTAB-TFILL, DIRTAB-FLENG.
      ENDLOOP.
    ELSE.
      WRITE 'Not found'.
    ENDIF.
    *******run this program and see the result.
    Hope this documentation will give you an idea of data cluster.
    if useful, do reward with the points.
    Regards,
    Kunal.

  • ERROR: Automation server can't create object

    Hi,
    I am at my wits end, and I hope you can help me. I have
    compiled a Webhelp project that runs just fine in Firefox (with the
    exception of expanding text but blah blah blah... :P)
    When I compile the same project in IE, I get an page loading
    error that tells me that "Automation server can't create object"
    (with reference to 'whskin_pdfhtml.html' in a file path, and my ToC
    is not visible.
    My tester, who is on another machine in another location,
    tells me HIS ToC loads fine, but he gets an out of memory error at
    line 59.
    I have trawled thru these forums for an hour now, and I am no
    closer to solving this problem. I have tried creating a brand new
    empty project with one topic and I get the same error.
    Any ideas on what's happening?
    Of course, we have a demo tomorrow at 6am.
    thanks

    Guessing here.
    1] You have created webhelp pro when you don't have RoboHelp
    Server installed on the server.
    2] Your source has some output files in it. The topic
    concerned being the one that gives the memory error. This result is
    what you get when you view in RoboHelp an output file that has been
    imported into the source. I don't know whether it gives the same
    error in the output again.
    Or are you viewing the help locally instead of from a server?
    What version of IE.

  • Ai CS4 & CS5: Can't move objects, huge memory usage. Tips?

    Okay guys this is my first post here, so bear with me.
    I'm just wondering if anyone can give guidance or refer me somewhere I can find a solution. I both CS4 and CS5 of Ai installed on my mac. Everything works just great, until I attempt to move an object. Something simple as a single line with freeze my system if I attempt to move it from one location to another.
    It is odd. I can scale/transform objects without any issue. Its just when I click an object to drag it to another location my system will freeze for about 5 seconds. The object won't move still. I opened up Activity Monitor and noticed my Memory usage sky rocketed as soon as I tried to move the object.
    Is there configurations for memory allocation in Illustrator like there is in photshop?
    (PS I have 3GB RAM and a 120GB HDD with 30GB free space, 2.0 Intel Core 2 processor, it's a 2007 Mac Mini)

    How big is the file? and is it complex if so then you simply do not have the resources. Also you might have a font cache issue.
    But I think the lack of resources.

  • Can anybody give me the table with tcode and its development class

    can anybody give me the table with tcode and its development class

    Hi phani,
    1) First retrieve program name from tstc table I.e field pgmna.
      2) Using pgmna retrieve from tadir table by using the following criteria from tadir table
       pgmid    = 'R3TR'
      AND object   = 'PROG'
      AND obj_name = tstc-pgmna.
    We will get development class or package in tadir i.e
    tadir-devclass 
    Thanks,
    Naveen Kumar.

  • How to resolve can't create object: 'OracleInProcServer.XOraSession'  ERROR

    Hello Everyone,
    We just replace our web server from windows server 2000 to windows server 2003 and we also
    upgrade our oracle database from 9i to 10g... But when i transfer all the asp pages into new server and
    run the scriprt i encountered error can't create object: 'OracleInProcServer.XOraSession' did i missed some of the requirements when doing this...
    I hope there someone will help me ragarding my problem.
    Thanks a lot

    user8794432 wrote:
    YES! I already upgrade the oracle client to 10g.. And im planning to install a OLE object OO40 for oracle 10g.
    Do you think this will work..?
    Well it was a suggestion. Give it a try. If it works, great. Else :-)

  • "Can't set object server" Error during SLD Initialization

    Hi,
    During System Installation at SLD configuration, problems occured and
    we skipped the step for later execution. After Installation and SPS13
    Application, we tried again but the following error occurs.
    Can't set object server
    com.sap.engine.interfaces.cross.ObjectReferenceImpl incompatible with
    com.sap.engine.services.applocking.LogicalLockingFactory
    Here I'm attaching the defaulttrace.log section produced during the error
    Defaulttrace.log
    tion#administrators#SAP-J2EE-Engine#administrators#
    #1.#001125BDBC10007600000028001420FA000443E69BC669DF#1200557641853#com.sap.lcr.webui.Admin#sap.com/com.sap.lcr#com.sap.lcr.webui.Admin#Administrator#6330##bporprod_BPP_1663750#Administrator#22947de0c4d411dccb66001125bdbc10#SAPEngine_Application_Thread[impl:3]_13##0#0#Error#1#/Applications/SLD#Plain###Can't set object server#
    #1.#001125BDBC10007600000029001420FA000443E69BC66ACD#1200557641853#com.sap.lcr.webui.Admin#sap.com/com.sap.lcr#com.sap.lcr.webui.Admin#Administrator#6330##bporprod_BPP_1663750#Administrator#22947de0c4d411dccb66001125bdbc10#SAPEngine_Application_Thread[impl:3]_13##0#0#Error##Plain###Thrown:
    java.lang.ClassCastException: com.sap.engine.interfaces.cross.ObjectReferenceImpl incompatible with com.sap.engine.services.applocking.LogicalLockingFactory
            at com.sap.rprof.dbprofiles.JDBCProfileLock.<init>(JDBCProfileLock.java:52)
            at com.sap.rprof.dbprofiles.JDBCProfileFactory.newProfileLock(JDBCProfileFactory.java:41)
            at com.sap.rprof.dbprofiles.RemoteProfile.getRemoteProfileFromFactoryForUpdate(RemoteProfile.java:230)
            at com.sap.lcr.start.EnvManager.getWriteableEnv(EnvManager.java:512)
            at com.sap.lcr.webui.Admin.actionInitialSetup(Admin.java:877)
            at com.sap.lcr.webui.Admin.doGet(Admin.java:231)
            at com.sap.lcr.webui.Admin.doPost(Admin.java:61)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
            at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
            at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:387)
            at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:365)
            at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:944)
            at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:266)
            at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
            at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)
            at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
            at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
            at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
            at java.security.AccessController.doPrivileged(AccessController.java:215)
            at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
            at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    #1.#001125BDBC10005F000092B3001420FA000443E69BE47659#1200557643822#com.sap.engine.services.security.roles.SecurityRoleImpl#sap.com/irj#com.sap.engine.services.security.roles.SecurityRoleImpl#Guest#6332####6047b4f0c44211dc8975001125bdbc10#Thread[Thread-53,5,SAPEngine_Application_Thread[impl:3]_Group]##0#0#Error#1#/System/Security/Audit/J2EE#Java###: Authorization check for caller assignment to J2EE security role [ : ].#3#ACCESS.ERROR#SAP-J2EE-Engine#administrators#
    does anyone faced the problem, and please a solution purpose
    regards

    defo an autorisation issue
    #1.#001125BDBC10005F000092B3001420FA000443E69BE47659#1200557643822#com.sap.engine.services.security.roles.SecurityRoleImpl#sap.com/irj#com.sap.engine.services.security.roles.SecurityRoleImpl#Guest#6332####6047b4f0c44211dc8975001125bdbc10#Thread[Thread-53,5,SAPEngine_Application_Threadimpl:3]_Group##0#0#Error#1#/System/Security/Audit/J2EE#Java###: Authorization check for caller assignment to J2EE security role : .#3#ACCESS.ERROR#SAP-J2EE-Engine#administrators#
    Where you assign the role depends on how you have setup your ume configuration - to the ABAP stack or have it managed in the Java stack
    If its just a java stack configuration for user management page of the java stack
    http://<servername>:50000/useradmin and give the user as many roles and permissions from there
    otherwise its PFCG in the abap stack of your system

  • Sorting a Vector.Can some one help please?

    Folks,
    How do I sort the elements in a Vector?
    If I have a vector containing different names,
    how can sort this out in ascending order?
    Please can any one send in a small example that I can
    modify to suit my requirments.
    Thanks
    Ajay

    u can only sort objects which implements the Comparable interface. the compareTo() method compares between 2 objects and returns a integer ranging from -1 to 1. -1 means smaller, 0 means equal and 1 means greater.
    you just have to follow your sorting algorithm, no extra changes needed. most classes implement the Comparable interface. if they dont, you can implement the interface yourself and override the compareTo() method.

  • Hwo can I insert objects in a transport request automaticly

    Hi all,
    I coded a program which changes some objects descriptions, it's working fine. But the problem is that I can't transport these modifications to another system without putting the objects in a transport request.
    So, How can I code that?
    Can some one give me a detailed example
    Thank you in advance.
    Amine

    Hi Michael,
    Thank you for your answer, but can you give me more details about these FMs.
    A sample code will be perfect
    Regards,
    Amine

  • Can you give names to groups?

    Can one give unique names to groups in a slide?

    I don't know how to move an object from it's starting position to another position on the screen. I know it can move off the screen but not to another position on the screen without a major workaround.

  • 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;

Maybe you are looking for

  • Ipod making weird noises and not working

    Ok so I recently have been having problems connecting my ipod to my computer. I plug it in to the usb cable, with itunes up. The ipod goes to the do not disconnect screen and itunes freezes. It stays like that and nothing changes. While this is happe

  • HR Report for viewing data transferred through CO1P transaction

    Hi, I have query here about HR data transfer which we do through CO1P transaction. How we can view these data transferred through CO1P in HR module i.e. any transaction or report is available from HR side which can give fair idea values which are pas

  • WebRequest not returning correct web page

    Hello, This is very strange, and I was hoping someone might have an answer/solution.  If you try the link below using a Chrome browser, you will get the correct web page returned, however any other browser (and my vb.net app's WebRequest) returns a r

  • Problem in adobe using  bapi BAPI_VENDOR_CREATE

    Dear Experts I  want to develop an adobe interactive  form for vendor creation using bapi " BAPI_VENDOR_CREATE "but all the necessary fields that needed for vendor creation are not coming.like fields in transaction code  'XK01'. i.e company name , tr

  • Oracle10.1.0 and gcc3.4.3 ,getString error

    environment: Red Hat Enterprise Linux AS release 4 (Nahant) Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 gcc3.4.3 ORACLE_HOME = /u01/app/oracle/product/10.1.0/db_1 compile command is: g++ -o a.out -I/u01/app/oracle/product/10.1.0/db_1/rd