XMLDecoder , unbound =Class.new(ArrayList, AttributeMap, ConnectionSet);

hello all i am trying to load an old files of my application
the files was written ,read using XMLDecoder ,XMLEncoder
trying to support the old version ,but i am getting some errors
i can only imagine , that some required classes are not suitable since the version change
but how can i know exactly witch class and witch method ?
this is the loading code
ClassLoader cl = new JARClassLoader();
          ExceptionListener el = new ExceptionListener() {
               public void exceptionThrown(Exception e) {
                    e.printStackTrace();
                    log.error("XMLDecoder error: " + mes + " -- " + e.getCause());
          XMLDecoder dec = new XMLDecoder(read, null, el, cl);
          Object obj = dec.readObject();///THIS LINE I GET THE ERRORthis is the error i am getting
java.lang.NoSuchMethodException: <unbound>=Class.new(ArrayList, AttributeMap, ConnectionSet);
     at java.beans.Statement.invoke(Unknown Source)
     at java.beans.Expression.getValue(Unknown Source)
     at com.sun.beans.MutableExpression.getValue(Unknown Source)
     at com.sun.beans.ObjectHandler.getValue(Unknown Source)
     at com.sun.beans.ObjectHandler.endElement(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
     at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
     at javax.xml.parsers.SAXParser.parse(Unknown Source)
     at javax.xml.parsers.SAXParser.parse(Unknown Source)
     at java.beans.XMLDecoder.getHandler(Unknown Source)
     at java.beans.XMLDecoder.readObject(Unknown Source)
     at com.tenlevels.flowlevel.util.ver_1_2_0_load.LoadGraph.loadGraph1(LoadGraph.java:100)
     at com.tenlevels.flowlevel.util.ver_1_2_0_load.LoadGraph.loadGraph(LoadGraph.java:61)
     at com.tenlevels.flowlevel.action.OpenFlow.doAction(OpenFlow.java:86)
     at com.tenlevels.flowlevel.action.ActionRouter.performAction(ActionRouter.java:79)
     at com.tenlevels.flowlevel.action.ActionRouter.access$0(ActionRouter.java:70)
     at com.tenlevels.flowlevel.action.ActionRouter$1.run(ActionRouter.java:64)
     at java.awt.event.InvocationEvent.dispatch(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)
java.lang.NullPointerException
     at org.jgraph.graph.AbstractCellView.getCellAttributes(Unknown Source)
     at org.jgraph.graph.AbstractCellView.refresh(Unknown Source)
     at org.jgraph.graph.GraphLayoutCache.refresh(Unknown Source)
     at org.jgraph.graph.GraphLayoutCache.refresh(Unknown Source)
     at org.jgraph.graph.GraphLayoutCache.insertViews(Unknown Source)
     at org.jgraph.graph.GraphLayoutCache.<init>(Unknown Source)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
     at java.lang.reflect.Constructor.newInstance(Unknown Source)
     at java.beans.Statement.invoke(Unknown Source)
     at java.beans.Expression.getValue(Unknown Source)
     at com.sun.beans.MutableExpression.getValue(Unknown Source)
     at com.sun.beans.ObjectHandler.getValue(Unknown Source)
     at com.sun.beans.ObjectHandler.eval(Unknown Source)
     at com.sun.beans.ObjectHandler.startElement(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
     at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
     at javax.xml.parsers.SAXParser.parse(Unknown Source)
     at javax.xml.parsers.SAXParser.parse(Unknown Source)
     at java.beans.XMLDecoder.getHandler(Unknown Source)
     at java.beans.XMLDecoder.readObject(Unknown Source)
     at com.tenlevels.flowlevel.util.ver_1_2_0_load.LoadGraph.loadGraph1(LoadGraph.java:100)
     at com.tenlevels.flowlevel.util.ver_1_2_0_load.LoadGraph.loadGraph(LoadGraph.java:61)
     at com.tenlevels.flowlevel.action.OpenFlow.doAction(OpenFlow.java:86)
     at com.tenlevels.flowlevel.action.ActionRouter.performAction(ActionRouter.java:79)
     at com.tenlevels.flowlevel.action.ActionRouter.access$0(ActionRouter.java:70)
     at com.tenlevels.flowlevel.action.ActionRouter$1.run(ActionRouter.java:64)
     at java.awt.event.InvocationEvent.dispatch(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)
java.lang.NullPointerException: target should not be null
     at java.beans.Statement.invoke(Unknown Source)
     at java.beans.Expression.getValue(Unknown Source)
     at com.sun.beans.MutableExpression.getValue(Unknown Source)
     at com.sun.beans.ObjectHandler.getValue(Unknown Source)
     at com.sun.beans.ObjectHandler.eval(Unknown Source)
     at com.sun.beans.ObjectHandler.startElement(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
     at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
...thank you

shay_te wrote:
ClassLoader cl = new JARClassLoader();
          ExceptionListener el = new ExceptionListener() {
               public void exceptionThrown(Exception e) {
                    e.printStackTrace();
                    log.error("XMLDecoder error: " + mes + " -- " + e.getCause());
          XMLDecoder dec = new XMLDecoder(read, null, el, cl);
          Object obj = dec.readObject();///THIS LINE I GET THE ERROR
I'd have to start out by saying: look in the API under object. readObject() is not an implemented method. Do you have an extension of Object that contains readObject()?

Similar Messages

  • List.clear() outside of List finalList = new ArrayList(); will delete element in finalList?

    Hello all!
    I am using 3 ArrayLists.
    the first is List<String>
    the second is List<String[]>
    and the third is a list of those lists List<List>
    I use the first list to get the string I need, but I use the second for String.split.
    I then need to keep a list of these to use, so I need the third List.
    After adding the second list to the list of lists I want to clear it so I can set up the next list to be added, but if I do list.clear(); it will delete everything in that list.
    If I do not clear it, it is fine.
    At first I wasn't sure if it was my fault, because I'm not sure if I ever had to do that before, so I made a test case that yields the result if I change the element outside.
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package javaapplication1;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    * @author Konrad
    public class JavaApplication1 {
         * @param args the command line arguments
        String a;
        List<String> j = new ArrayList<>();
        public JavaApplication1()
            a();
        public void a()
            a = "ADASDSADSA";
            j.add(a);
            a = null;
            System.out.println(j);
        public static void main(String[] args) throws SQLException {
            JavaApplication1 a = new JavaApplication1();
    If I change a = null to a = ""; it still yields the original a = "ADASD......";
        protected List<String> list = new ArrayList<>();
        protected List<String[]> list2 = new ArrayList<>();
        protected List<List> finalList = new ArrayList<>();
      finalList.add(list2);
                     //list2.clear();
    With this I yield an empty array element, even though my array elements exist.  I tried using multiple lists and I just had multiple empty elements.
    So again I'm not sure if I did something wrong, or is this a bug?  Since my test case worked, I'm confused.
    Thanks!
    ~KZ

    After adding the second list to the list of lists I want to clear it so I can set up the next list to be added, but if I do list.clear(); it will delete everything in that list.
    Correct - you are just working with multiple references to the SAME set of objects.
    Use 'remove' to remove an element from a list and then 'add' to add it to the other list.
    See the Javadocs for the 'remove' method of the List interface
    http://docs.oracle.com/javase/6/docs/api/java/util/List.html#remove(int)
    remove
    E remove(int index)
    Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.   
    Parameters: 
    index - the index of the element to be removed 
    Returns: 
    the element previously at the specified position 
    Throws: 
    UnsupportedOperationException - if the remove operation is not supported by this list 
    IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())

  • Serialization of the class with ArrayList

    Hello,
    I'm new to java. I'm trying to serialize this class;
    public class TestClass {
        public ArrayList<String> list = new ArrayList<String>();
    }with this code:
    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(baseName));
            TestClass proba = new TestClass();
            out.writeObject(proba);
            out.close();it fails;/
    Do you know why? If i serialize only object like this:
    ArrayList<String> list = new ArrayList<String>();everything works well.
    What am i doing wrong?
    Cheers!

    it failsFails how?
    Do you know why?We don't even know how it fails, how can we possibly know why?
    If i serialize only object like this:
    ArrayList<String> list = new ArrayList<String>();everything works well.The difference being that the one that fails is public?
    What am i doing wrong?What is going wrong?
    If you got a bug report like that from a user would you accept it? 'It fails'?

  • JSTL unable to retieve class of ArrayList

    Let's say that i add an attribute in the request scope like this :
    request.setAttribute("myList", new ArrayList());
    Why does the following code crashes?
    <c:out value="${requestScope.myList.class.name}"/>
    When the following doesn't :
    <%= request.getAttribute("myList").getClass().getName() %>

    Its not a bug, its a FEATURE! This is defined
    functionality: JSTL is being helpful :-)Sorry but i don't understand how helpul that is. We could use backets to access elements in the list : ${myList[0]}. I thought period were reserved for accessing properties the "bean way". That forces the developer to handle exceptions when he writes generic code.
    ie myList.0 would retrieve the first element in the
    list.Well i tried this but it's not working either :
    <c:out value="${myList.0}" /> generates the following error
    javax.servlet.jsp.el.ELException: Encountered ".0", expected one of ["}", ".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||", "?"]
    When you use ${myList.class} it tries to turn
    "class" into an integer, fails miserably and throws
    an error.Indeed it does :-(
    So any idea how i could retrieve the className of all objects placed in requestScope without having to handle exception ??

  • Unbound Class Variable Error

    Hi All,
    I am doing a webdynpro application. while deploying, it gives me an error
    "Unbound class Variable:'KMC_LIBS/bc.srf.framework_api.jar'.
    What is this error?
    Regards,
    Divya

    Hi,
    A Classpath Variable is just a variable which points to a directory in your file system.
    Useful when 1st developer has external jars on path1 and 2nd developer has external jars on path2 (the two paths are different) and the developers want to prevent classpath issues.
    In NWDS go to:
    Window -> Preferences -> Java -> Classpath Variables and check if 'KMC_LIBS' points to a directory.
    Also, you can delete this entry from your project's classpath and add the file 'bc.srf.framework_api.jar'' manually (without classpath variable).
    Regards,
    Omri

  • Combining two ArrayLists of Integers into a new ArrayList.

    Basicly I have two arrayLists that have a list of numbers and I want to add them both into one new arrayList in the same index. Example
    aList1 = [ 4 , 5 , 10 , 33 ]
    aList2 = [ 1 , 3 , 19 ]
    combinedList = aList1 + aList2
    print out combinedList = [4,5,10,33,1,3,9]
    That's what I want out of it but the only way I can do this is if I write
    combinedList.add[aList1]
    combinedList.add[aList2]
    but it would come out like [ 4 , 5 , 10 , 33 ] [ 1 , 3 , 19 ]. Two seperate indexs holding a list of Integers. Where I need it to be [4 , 5 , 10 , 33 , 1 , 3 , 9]
    Which is incorrect cause they are in seperate indexs. I need to place both of them into the same index starting with all the numbers for aList1 and then aList2.
    I could just go through each aList1 index and placed each one into a new arrayList and then do that with aList2 but I'm trying to make this a little more efficient than that. I tried using addAll but it seems to add each arrayLists as an object and that just comes out like 2. Here's some of the code from by program.
    Collections.sort(alist1);
    Collections.sort(alist2);
    aNewList.add(alist1);
    aNewList.add(alist2);   
    return aNewList;Like I said I could do it the long way but I'm trying to keep the complexity to a minimum. Any help would be very much appreciated. Thanks :)
    Edited by: DavidMilot on Oct 18, 2008 6:08 PM

    DavidMilot wrote:
    Not to be rude I just cannot copy and paste all my code into the forum out of fear of plagerism.I didn't mean for you to post all of your code. Just a small program that demonstrates the problem. This program would have 3 arraylists on it, 2 filled, one empty that would receive the other two. You combine them, print out the third and that's it.
    I could rename all my variables and method names but I unfortunately don't have time to do all that because I have 3 midterms coming in 3-4 days. This doesn't seem to be an easy fix just by giving out minimal code (which the names have been altered) but I still appreciate the effort. For now I tend to leave the code the way it is havingThe onus of effort here must be yours.
    newList.add(aList1)
    newList.add(aList2)
    It's not perfect but that's as close as I can get for now. Plus this assignment is due monday hehe. Feel free to continue giving me ideas to try out I plan to ask my TA monday before handing it in. Thanks again.I mainly wanted to see is if you are using addAll two add both aList1 and aList2. For some unknown reason in the code you posted before you didn't. Again, lord knows why.

  • LinkedList class and ArrayList class

    Hi everyone,
    What is difference between LinkedList class and ArrayList class ??

    Hi samue!
    If you had typed that question you would have got many answers.anyway
    difference between Linked List and ArrayList
    1.In linked list each element is stored as an object but not in arraylist
    2.Linked list need iterator to go through its contents but not arraylist
    3.reading element from each takes same time but if you want to add or remove element from the arraylist it takes considerable amount of time depending on the index number. in Linkedlist case it takes constant amount of time to add/remove at any index.
    this should be enough guess to know the difference but if u need try goooogle

  • ArrayList - clear() or new ArrayList() ?

    Hi everybody,
    I have a loop which runs ~100-100000 times and in each looping an ArrayList is filled and holds elements ranging from 1 to 30000. I'm reusing the list and I'm wondering whether I should use clear() or better reinstantiate the List.
    I know that with StringBuffer the setLength(0) does not decrease the capacity of the StringBuffer, so that it might take much more memory than it actually needs.
    How about List?
    Does clear() decrease the capacity of the List?
    Would a reinstantiation be the better way?
    Or doesn't it matter anyway and a list with too much capacity is fine to use?
    Hope you can help
    Cheers
    bgcl

    Hi everybody,
    I have a loop which runs ~100-100000 times and in each
    looping an ArrayList is filled and holds elements
    ranging from 1 to 30000. I'm reusing the list and I'm
    wondering whether I should use clear() or better
    reinstantiate the List.
    I know that with StringBuffer the setLength(0) does
    not decrease the capacity of the StringBuffer, so that
    it might take much more memory than it actually
    needs.
    How about List?
    Does clear() decrease the capacity of the List?
    Would a reinstantiation be the better way?
    Or doesn't it matter anyway and a list with too much
    capacity is fine to use?
    Hope you can help
    Cheers
    bgclclear() will be better than new ArrayList() but the performance difference of clear() and new ArrayList(int) (with an int of an appropriate size) will be negligable.

  • ReportPart class new XIR2 SP2 webservices SDK

    <font face="Arial" size="2"><p align="left">The following information is quoted from the BO XIR2 SP2 and Productivity Pack Release Note Chapter 8. I am interested in the following two class addtions. But I can&#39;t seem to be able to find them in the web services SDK java reference as describle in the release note. Can anyone kindly tell me where I should be looking at for the new classes documentation. </p><p align="left"> Thanks in advance,</p><p align="left">The following APIs are added in this release. For more information on these APIs, refer to Java API Reference at <font face="Arial" size="2" color="#0079da"><a href="http://devlibrary.businessobjects.com/">http://devlibrary.businessobjects.com</a></font></p></font><font face="Arial" size="2" color="#0079da"><font face="Arial" color="#009ccf"><p align="left">u2022 <strong><font color="#000000"><font face="Arial,Bold" size="1">ReportPart</font><font face="Arial,Bold" size="2">: </font><font face="Arial" size="2">The </font><font face="Times New Roman" size="1">ReportPart </font></font></strong><font face="Arial" size="2"><font color="#000000">class helps you in accessing a particular<br /></font>part of a report. For example, a section or table in a report.</font></p></font><font face="Arial" color="#009ccf"><p align="left">u2022 <strong><font color="#000000"><font face="Arial,Bold" size="1">NavigateToReportPart</font><font face="Arial,Bold" size="2">: </font><font face="Arial" size="2">The </font><font face="Times New Roman" size="1">NavigateToReportPart </font></font></strong><font face="Arial" size="2"><font color="#000000">class is used to<br /></font>navigate to a particular part of a report. To view the corresponding report part, you must retrieve a particular </font><font face="Times New Roman" size="1">ReportPartReference </font><font face="Arial" size="2">from the XMLView of the report and set it to </font><font face="Times New Roman" size="1">RetrieveView </font><font face="Arial" size="2">instance using </font><font face="LetterGothicMT" size="1">setReportPartReference</font><font face="Arial" size="2">() (For .NET, </font><font face="LetterGothicMT" size="1">ReportPartReference</font><font face="Arial" size="2">) method.</font></p></font></font>

    Those classes, as you saw, are new to Web Services ReportEngine API with Service Pack 2.
    Unfortunately, the on-line documentation is currently based on CHF15, and is yet to be updated for Service Pack 2.
    I've heard it should be updated in a few days.
    Thank you for your patience.Â
    Ted Ueda

  • ECLIPSE & NETBEANS Same error about android.R class - new project

    %JAVA_ANT%/bin %JAVA_HOME%/bin
    ANDROID DEV - ALL NEW PROJ STARTUP CODE - GIVE ERROR
    prior run ok and could create hellow word Android projects (no add anything) but now cannot run. ECLIPSE & NETBEANS Same error about android.R class,... As remember I installed ant in C:/Ant from Apache zip file for Phonegap. Ant exist and to JDK? BOTH far above must set in WINDOWS 7 64bit System - environmental vars??? I think something deleted i guess ant in environmental vars...
    In eclipse juno where are Android sdk tools and AVM ??%JAVA_HOME% how understand what this holds?
    this posted and here but no reply - see the attachment here:
    Android Forums at AndroidCentral.com

    You may want to swap out OpenJDK for the official version as compatibility isn't always guaranteed - any sort of development would require the "proper" java stack in my opinion.
    Apologies - tomcat does need to be installed separately. It is quite a while since I have had to reinstall netbeans / reconfigure it  
    Have you configured tomcat and have it running without error in the background?
    https://wiki.archlinux.org/index.php/Tomcat
    https://wiki.archlinux.org/index.php/Netbeans

  • Data class/ New DB space

    BW Experts,
    Does anyone know how to create a new 'Data Class' in SAP BW. The scenario is that the DBA have created new DB Tablespace, and i need to create new data class and assign it to these new DB space.
    Any idea? help is appreciated.
    Thanks
    ASHWIN

    Aashwin
    Check this if it helps. I think this also will be done by DBA
    Thnaks
    Sat
    http://help.sap.com/saphelp_nw04/helpdata/en/0d/ed6258a0364845829ff51ee22fb4ae/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/0d/ed6258a0364845829ff51ee22fb4ae/frameset.htm
    Thnaks
    Sat

  • XMLEncoder usage for Java to XML Serialization

    I have recently started using XMLEncoder and XMLDecoder to perform Java Bean to XML Serialization and Deserialization. It seems to break when multiple threads are using XMLEncoder, even if each Thread is using a separate instance of XMLEncoder. I was initially seeing NullPointer exception and after obtaining a fix for that IBM Support, we are seeing various other exceptions like this.
    java.lang.IllegalAccessException: Can not call newInstance() on the Class for java.lang.Class
    java.lang.Exception: discarding statement XMLEncoder0.writeObject(TestObject0);
    java.lang.Exception: discarding statement XMLEncoder0.writeObject(TestObject0);
         at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:352)
         at java.beans.XMLEncoder.writeObject(XMLEncoder.java:266)
         at test.XMLEncoderIssue.run(XMLEncoderIssue.java:59)
         at java.lang.Thread.run(Thread.java:570)
    Caused by: java.lang.RuntimeException: failed to evaluate: <unbound>=Class.new();
    java.lang.ArrayIndexOutOfBoundsException: 0
    at java.beans.ObjectHandler.dequeueResult(XMLDecoder.java:285)
    at java.beans.XMLDecoder.readObject(XMLDecoder.java:163)
    at test.XMLEncoderIssue.run(XMLEncoderIssue.java:75)
    at java.lang.Thread.run(Thread.java:570)
    What am i missing here?

    Just add an empty constructor in your class

  • Dynamic casting

    hello all (happy new year!),
    i am trying to dynamically cast a class that is only known at runtime from the configuration file that is parsed during startup.
    the code is as follows:
    ArrayList classes = new ArrayList();
    ... (parsing)
    classes = JAFSaxParserInstance.getClasses();
    Iterator it = classes.iterator();
    while (it.hasNext())
      Object next = it.next();
      Class appToLoad = Class.forName(next.toString());
      Method instanceMethod = getInstanceMethod(appToLoad);
      Object frame = instanceMethod.invoke(null,null);
      Component[] components = new Component[MAX];
      components = ((UNKNOWN_CLASS) frame).getContentPane().getComponents();
    }without the ability to discover the class from which i have just called a getInstance() method, i seem unable to retrieve all the components of the JFrame subclass (i get a ClassCastException). for my purposes, all of the UNKNOWN_CLASSes will be subclasses of JFrame, but without explicitly being able to cast it (frame) exactly, i cannot extract the components.
    is there any way to dynamically cast such objects at runtime? by this i mean i cannot use switch statements b/c the classes are unknown prior to runtime.
    thanks!

    point well taken. i've probably designed my application wrong if it's this difficult, but let me try to explain what it is i'm trying to do.
    i had previously created a swing application whose central class (bootstrap initialized by a separate class with a main method) is a subclass of JFrame using the GridBagLayout manager. now, since more related gui applications are to be built, i thought it would be nice to build an application framework into which i could insert each standalone application into a JTabbedPane pane of the framework application.
    the application framework has the same structure as my previous application. a bootstrap main method class initializes the main application frame which builds a contentPane which contains a JTabbedPane. as this application framework frame is initializing, it parses an xml file which contains the data pertaining to each class and my DynamicLoader class attempts to load/initialize and add each class into a separate tab in the main application frame. that's where the problem arises since i don't know the exact class that will be loaded--only the xml file contains that information.
    i've read a few things about implementing interfaces in order to get around the inability to cast types at runtime, but am not too sure of how that might work.
    let me know if seeing some more of the code would help or if there's anything i should clarify.
    thanks!

  • Doing without Generics - ideas??

    HI everyone,
    I (unfortunately) can not use Generics in the current project I'm working on but am facing a problem that I feel would be best solved by Generics. In fact, the existing C++ versions works a charm using the parameterized approach.
    Problem: C++ Objects are created from XML specifications of classes. Want to now create from these specs, Java objects.
    small example,
    <class name="Foo">
    <field name="SomeVar">
    <type = "list">
    <list-subtype type="string">
    </list>
    </field>
    </class>
    This would create Foo.{cpp,h} with
    std::list<std::string> SomeVar;
    The other side of the problem is turning the object back into
    the XML specification.
    I have been thinking about how best to design for this problem, but keep
    getting stuck on aspects such as lists of maps. IN c++ you know the element types in the list (or can work it out), but in Java it's a different story.
    Should I implement type-safe classes such as StringList, IntegerList
    etc.. which restrict access to the LinkedList they each hold? Or should I just rely on reflection and subsequently call (possible) hundreds of different methods. A speed is a major consideration, the fewer calls the better.
    I would appreciate any input you have on this point.
    Cheers

    i dont't fully understand the problem. how would these generated classes be used, by human programmers or by generated code? supposing human programmers, is the contents of collections your only problem? if this is so and you want to guarantee the content type, there's a simple solution. write wrappers for the collection interfaces you use that type-check elements, keys and values on input to the backing collection. make the constructor take the backing collection and the element type(s) (Class object(s)) as arguments, and every time an element, key or value is to be inserted into the collection, validate them using something like:
    if (!type.isInstance(obj))
         if (obj == null) throw new NullPointerException();
         else throw new ClassCastException();
    or:
    if (!type.isInstance(obj) && obj != null) throw new ClassCastException();
    if you want to accept nulls. of course, when you get objects from the collection you'll have to cast, but the collection contents will be sort of type-safe.
    as i said i dont't fully understand the problem, and don't think this will help much, but if it does, let me give you some pointers. safe wrapper implementations may be a bit trickier than you think, specially the MAP wrapper which involves wrapping several views, iterators and MAP.ENTRYs, and has to witstand subtle attacks like evil equals() implementations. use the source code for the Collections.unmodifiableXxx() wrappers as a starting point. these wrappers stop all mods, so you'll just have to put the tests in and you are done. then you can generate code like:
    List someVar = TypedCollections.typedList(String.class, new ArrayList());
    alternatively you may use factories. using factories, if you later find that typed LinkedLists are used a lot and the wrapping impacts performance, you could optimize by making the factory return a specilized typed implementation for that case (based on/extending LinkedList), but i really don't think it would be worth the effort.
    you may later need type info from the collection, so maybe you want say interface TypedCollection (extending Collection) and TypedMap (extending Map) implemented by these wrappers. the interfaces have getters to return element, key or value type info. but note that if you use other wappers (like unmodifiable) you'll lose the chance to query this info (unless you extend those wrappers yourself, of course).
    i hope some of this stuff helps, but it probably won't. so what? cheers!!

  • Create a JTable based on an ArrayList containing instances of a class.

    I have a class, IncomeBudgetItem, instances of which are contained in an ArrayList. I would like to create a JTable, based on this ArrayList. One variable is a string, while others are type double. Not all variables are to appear in the JTable.
    The internal logic of my program is already working. And my GUI is largely constructed. I'm just not sure how to make them talk to each other. The actually creation of the JTable is my biggest problem right now.

    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.util.ArrayList;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    public class TableDemo extends JPanel {
         private boolean DEBUG = false;
         public TableDemo() {
              super(new GridLayout(1, 0));
              ArrayList<MyObject> list = new ArrayList<MyObject>();
              list.add(new MyObject("Kathy", "Smith", "Snowboarding", new Integer(5),
                        new Boolean(false)));
              list.add(new MyObject("John", "Doe", "Rowing", new Integer(3),
                        new Boolean(true)));
              list.add(new MyObject("Sue", "Black", "Knitting", new Integer(2),
                        new Boolean(false)));
              list.add(new MyObject("Jane", "White", "Speed reading",
                        new Integer(20), new Boolean(true)));
              JTable table = new JTable(new MyTableModel(list));
              table.setPreferredScrollableViewportSize(new Dimension(500, 70));
              table.setFillsViewportHeight(true);
              // Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);
              // Add the scroll pane to this panel.
              add(scrollPane);
         class MyObject {
              String firstName;
              String lastName;
              String sport;
              int years;
              boolean isVeg;
              MyObject(String firstName, String lastName, String sport, int years,
                        boolean isVeg) {
                   this.firstName = firstName;
                   this.lastName = lastName;
                   this.sport = sport;
                   this.years = years;
                   this.isVeg = isVeg;
         class MyTableModel extends AbstractTableModel {
              private String[] columnNames = { "First Name", "Last Name", "Sport",
                        "# of Years", "Vegetarian" };
              ArrayList<MyObject> list = null;
              MyTableModel(ArrayList<MyObject> list) {
                   this.list = list;
              public int getColumnCount() {
                   return columnNames.length;
              public int getRowCount() {
                   return list.size();
              public String getColumnName(int col) {
                   return columnNames[col];
              public Object getValueAt(int row, int col) {
                   MyObject object = list.get(row);
                   switch (col) {
                   case 0:
                        return object.firstName;
                   case 1:
                        return object.lastName;
                   case 2:
                        return object.sport;
                   case 3:
                        return object.years;
                   case 4:
                        return object.isVeg;
                   default:
                        return "unknown";
              public Class getColumnClass(int c) {
                   return getValueAt(0, c).getClass();
          * Create the GUI and show it. For thread safety, this method should be
          * invoked from the event-dispatching thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("TableDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Create and set up the content pane.
              TableDemo newContentPane = new TableDemo();
              newContentPane.setOpaque(true); // content panes must be opaque
              frame.setContentPane(newContentPane);
              // Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              // Schedule a job for the event-dispatching thread:
              // creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();
    }

Maybe you are looking for