StackOverflowError with HashMap

We are experiencing a problem where we get a StackOverflowError after recursing too many times in a HashMap. It's quite a deep recursion, from what I can tell, over 1024 times.
The odd thing is that we are only getting this error on a Windows machine. We tested it on a Linux machine and it works fine with no errors.
Does anyone know of a problem like this on a Window machine, and how to fix it?
Thanks!

Here's the stack trace:
Parsing "test.xml"... Exception in thread "main" java.lang.StackOverflowError
at java.util.HashMap.containsKey(Unknown Source)
at java.util.HashSet.contains(Unknown Source)
at our.package.XRef.remove(XRef.java:410)
at our.package.XRef.access$000(XRef.java:16)
at our.package.XRef$Entry.setObject(XRef.java:112)
at our.package.XRef.addObject(XRef.java:297)
at our.package.XRef.mark(XRef.java:191)
at our.package.XRef.mark(XRef.java:199)
at our.package.XRef.mark(XRef.java:199)
at our.package.XRef.mark(XRef.java:199)
at our.package.XRef.mark(XRef.java:199)
at our.package.XRef.mark(XRef.java:199)
at our.package.XRef.mark(XRef.java:199)
etc, etc, for about 1000 lines....
If I put a try... except block in the XRef.remove method, I can't even catch the error, which is extremely odd. Which also means the error must be coming from somewhere else, but I don't know where.
I'm running with the lastest release of the JVM 1.5, on a Windows XP P4 with over 700MB RAM.

Similar Messages

  • Urgent:Issue with HashMap while creating session in Java Embedding Activity

    Hi,
    I am unable to createsession() with the values from HashMap. following is the code in JEA
    IAgileSession m_session=null;
              IAdmin admin = null;
              IAgileClass cls = null;
              IAutoNumber[] numSources;
              String nextAutoNumber = null;
    try {
                   HashMap params = new HashMap();
                   params.put(AgileSessionFactory.USERNAME, "*********");
                   params.put(AgileSessionFactory.PASSWORD, "*******");
    int s= params.size();
    String y= (String)params.get(AgileSessionFactory.USERNAME);
    String z= (String)params.get(AgileSessionFactory.PASSWORD);
    addAuditTrailEntry("UserName " +y);  
    addAuditTrailEntry("Password " +z);  
    addAuditTrailEntry("Size is " +s);   
                   AgileSessionFactory instance = AgileSessionFactory.getInstance("******************************");
    addAuditTrailEntry("After instance object" +instance);
    m_session = instance.createSession(params);
    addAuditTrailEntry("" +m_session);
    addAuditTrailEntry("After instance object_Session");
                   admin = m_session.getAdminInstance();
                   cls = admin.getAgileClass( "ProblemReport" );
                   IServiceRequest psr = (IServiceRequest)m_session.createObject( "ProblemReport", "PR-9989909");     
              } catch (Exception e) {
                   e.printStackTrace();
              } finally {
                   m_session.close();
    In the above code it is working perfectly up to AgilSessionFactory instance, but after that when I am printing m_session ( i.e. addAuditTrailEntry("" +m_session);) it is returning null values instead of some session ID. I am also able to print AgilesessionFactoy instance ID correctly inside JEA, but only problem is with m_session. I tried with the same code in java client and it is working perfectly. Please some one help me in this issue.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hi,
    I am unable to createsession() with the values from HashMap. following is the code in JEA
    IAgileSession m_session=null;
              IAdmin admin = null;
              IAgileClass cls = null;
              IAutoNumber[] numSources;
              String nextAutoNumber = null;
    try {
                   HashMap params = new HashMap();
                   params.put(AgileSessionFactory.USERNAME, "*********");
                   params.put(AgileSessionFactory.PASSWORD, "*******");
    int s= params.size();
    String y= (String)params.get(AgileSessionFactory.USERNAME);
    String z= (String)params.get(AgileSessionFactory.PASSWORD);
    addAuditTrailEntry("UserName " +y);  
    addAuditTrailEntry("Password " +z);  
    addAuditTrailEntry("Size is " +s);   
                   AgileSessionFactory instance = AgileSessionFactory.getInstance("******************************");
    addAuditTrailEntry("After instance object" +instance);
    m_session = instance.createSession(params);
    addAuditTrailEntry("" +m_session);
    addAuditTrailEntry("After instance object_Session");
                   admin = m_session.getAdminInstance();
                   cls = admin.getAgileClass( "ProblemReport" );
                   IServiceRequest psr = (IServiceRequest)m_session.createObject( "ProblemReport", "PR-9989909");     
              } catch (Exception e) {
                   e.printStackTrace();
              } finally {
                   m_session.close();
    In the above code it is working perfectly up to AgilSessionFactory instance, but after that when I am printing m_session ( i.e. addAuditTrailEntry("" +m_session);) it is returning null values instead of some session ID. I am also able to print AgilesessionFactoy instance ID correctly inside JEA, but only problem is with m_session. I tried with the same code in java client and it is working perfectly. Please some one help me in this issue.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • SelectMany checkbox value-binded with HashMap String,ArrayList

    Hello,
    Someone can help me please?
    Im trying to create a page with a lot of HtmlSelectManyCheckbox, and i need to value-bind then to the same Object in my BackingBean.
    First i attemped to bind all HtmlSelectManyCheckbox with a single ArrayList, but only the last SelectMany had their values inserted on the ArrayList...
    So, now im trying to bind all the HtmlSelectManyCheckbox with a HashMap<String,ArrayList>, because i would have just one object and for each entry I would have the checkboxes that were cheked in a single HtmlSelectManyCheckbox.
    Now my question: there is a way to make this work?
    my code example
    Backing bean
    private HashMap<String, ArrayList> respostaMatrizCheck = new HashMap<String, ArrayList>();
         public HashMap<String, ArrayList> getRespostaMatrizCheck() {
              return respostaMatrizCheck;
         public void setRespostaMatrizCheck(HashMap<String, ArrayList> respostaMatrizCheck) {
              this.respostaMatrizCheck = respostaMatrizCheck;and the bindings
    <h:selectManyCheckbox value="#{backingBean.respostaMatrizCheck['1'] }">
    <h:selectManyCheckbox value="#{backingBean.respostaMatrizCheck['2'] }">And the error message given when i tryed this is the following:
    javax.servlet.ServletException: ValueBinding for UISelectMany must be of type List or Array
    Any help would be welcome.
    Thanks,
    Ferry

    Has anybody solved a problem like this? I am facing the same problem and no response helped me so far.
    Here is the web code:
    <h:selectManyCheckbox value="#{processor.languages.languages1}">
         <f:converter converterId="languageConverter" />
         <f:selectItems value="#{categoryController.allLanguagesAsSelectItems}" />
    </h:selectManyCheckbox>My backing bean "processor" looks like this:
         public Map<String, List<MyObject>> getLanguages() {
              return languagesMap;
         }(The backing bean has no "setLanguages()-method" since I did not need any with Map<String, String> for example.)
    The converter I use creates a "MyObject" instance in its "getAsObject" conversion method.
    I think everything should be okay then but the exception I get after submitting the page is:
    java.lang.IllegalArgumentException: ValueBinding for UISelectMany must be of type List or Array
         org.apache.myfaces.shared_impl.renderkit._SharedRendererUtils.getConvertedUISelectManyValue(_SharedRendererUtils.java:191)
         org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedUISelectManyValue(RendererUtils.java:630)
         org.apache.myfaces.shared_impl.renderkit.html.HtmlCheckboxRendererBase.getConvertedValue(HtmlCheckboxRendererBase.java:308)
         javax.faces.component.UISelectMany.getConvertedValue(UISelectMany.java:308)
         javax.faces.component.UIInput.validate(UIInput.java:350)
    .....Edited by: rapthor on Oct 31, 2007 6:39 AM

  • StackOverflowError with XMLEncoder on my objects.

    Works fine when I run the example:
    XMLEncoder e = new XMLEncoder(
    new BufferedOutputStream(
    new FileOutputStream("Test.xml")));
    e.writeObject(new JButton("Hello, world"));
    e.close()
    but when i run my little class I get java.lang.StackOverflowError below.
    Could anyone help? (I'm new to XMLEncoder and relatively new to JavaBeans).
    Thanks in advance.
    Morten
    java.lang.StackOverflowError
    at java.lang.Class.getMethod0(Class.java:1756)
    at java.lang.Class.getMethod(Class.java:963)
    at java.beans.Statement.findPublicMethod(Statement.java:230)
    at java.beans.Statement.findMethod(Statement.java:270)
    at java.beans.Statement.getMethod(Statement.java:366)
    at java.beans.Statement.invoke(Statement.java:439)
    at java.beans.Expression.getValue(Expression.java:101)
    at java.beans.Encoder.getValue(Encoder.java:84)
    at java.beans.Encoder.get(Encoder.java:186)
    at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:97)
    at java.beans.Encoder.writeObject(Encoder.java:55)
    at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
    at java.beans.Encoder.writeExpression(Encoder.java:260)
    at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363)
    at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
    at java.beans.Encoder.writeObject(Encoder.java:55)
    at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
    at java.beans.Encoder.writeExpression(Encoder.java:260)
    at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363)
    at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
    at java.beans.Encoder.writeObject(Encoder.java:55)
    at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
    at java.beans.Encoder.writeExpression(Encoder.java:260)
    at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363)
    at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
    at java.beans.Encoder.writeObject(Encoder.java:55)
    at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
    at java.beans.Encoder.writeExpression(Encoder.java:260)
    at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363)
    at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
    at java.beans.Encoder.writeObject(Encoder.java:55)
    at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
    at java.beans.Encoder.writeExpression(Encoder.java:260)
    at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363)
    at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
    at java.beans.Encoder.writeObject(Encoder.java:55)
    at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
    at java.beans.Encoder.writeExpression(Encoder.java:260)
    at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363)
    at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
    at java.beans.Encoder.writeObject(Encoder.java:55)
    at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
    at java.beans.Encoder.writeExpression(Encoder.java:260)
    at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363)
    at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
    at java.beans.Encoder.writeObject(Encoder.java:55)
    at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
    at java.beans.Encoder.writeExpression(Encoder.java:260)
    at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363)
    at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
    ...

    I think the problem here may be that the BeanBox does not
    remove itself as a listener from its components before it
    tries to serialise them. The XMLEncoder works out that the
    JellyBean and co have listeners (because they are derivatives
    of Component - which has a getListeners() method) and will attempt
    to serialise those listeners. I suspect that one of these is
    the BeanBox itself - or a component inside it. If that component
    also knows about the beans it contains there is a possibility
    the archiving process will loop - though somthing odd is happening
    as the XMLEncoder should detect identical instances in the object
    graph and mark them with an "idref" attribute - rather than looping.
    It may be that the BeanBox clones part of itself when certain
    getters are called. (I don't have your code so this is all a
    bit of a guess.)
    Anyway, if you want to look at this sort of thing a better
    place to start is the BeanBuilder which is availible on the
    SwingConnection website. The BeanBox predates all of the
    archiving work - whereas the BeanBuilder was purpose built to
    demonstrate it and the other new features in SDK 1.4.
    Hope that helps.
    Philip

  • UISelectMany - Conversion error with HashMap Property

    Hi,
    I have a Backing Bean with a HashMap Property.
    public HashMap getItem()
    public void setItem(HashMap map)
    so I bind a Value of an UIInputText Component like that:
    <h:inputText id="txtname" value="#{MyBean.item['myKey']}" />
    this works pretty well.
    But when I try to do the same with an <h:selectManyCheckbox> Component I got a "Conversion Error".
    For what reason? I expected an Array or List Object.
    Thanks for help
    Ralph

    I solved the problem by creating a custom converter, which checks if the current valueBinding is null.
    If so, it replace the valueBinding with an empty ArrayList().
    public class MultiValueConverter implements Converter {
         public final static String CONVERTER_ID = "org.imixs.workflow.j2ee.faces.MultiValueConverter";
         public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
    // no changes
    return value;
         public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException {
    // Check if current value Binding is bind to an null-Object
    javax.faces.el.ValueBinding valueBinding=component.getValueBinding("value");
    if (valueBinding!=null && valueBinding.getValue(context)==null) {
    // replace binding with empty ArrayList
    valueBinding.setValue(context,new ArrayList());
    // no changes
    return value.toString();
    you can find the full code under www.imixs.org (an open source project for a EJB based workflow engine)

  • Would like some help with hashmaps please :)

    Map<Integer, Double> probabilities = new HashMap<Integer, Double>();When i try to use the above code in a foreach loop
    for (Map.Entry<Integer, Double> entry : probabilities)i get this error
    Foreach not applicable to expressionCould anyone please enlighten me on what is wrong with that and maybe suggest another way of running through the HashMap.
    THANKS!

    for (Map.Entry<Integer, Double> entry : probabilities.entrySet())

  • I have problems with HashMap

    hello guys
    i have a problems whith this assignment.
    im usunig BlueJ
    its about a library has members and lists of the books available( a catalogue for viewing by members) and of the copies of
    these (for stock control purposes).
    information of a book (title, author, and ISBN), the title is a unique identifier.
    a book may have several copies, each with a unique stock number (an integer). a book may have no copies (if, for
    example, it has been added to the catalogue, but copies havent yet arrived.
    the library most be able to:
    - add a book to the catalogue for example when its newly published.
    - add a copy of a book to its stock when the library receives this item.
    - obtain a list of copies of a book, given its title.
    - obtain a String representation of the list of copies of a book, given its title; this should just be the title
    and list of stock numbers, for examble :( title, copies: 2000, 2001, 2002).
    now i cant make the HashMap for the stock items,
    is there anything wrong i have made or any suggestions to help me to continue my work?
    the two classes i have made so far:
    public class books
        private String title;
        private String author;
        private String ISBN;
        private int quantity;
        private int stockNumber;
        public books(String title, String author, String ISBN)
            this.title = title;
            this.author = author;
            this.ISBN = ISBN;
            //stock number satrts from 2000
            stockNumber = 1999;
        public int addquntity (int amount)
                quantity = quantity + amount;
                return quantity;
        // chang the quantity when costumer borrows a book from the library
        public int getBorowed()
            if(quantity > 0){
              quantity --;
            else{
                System.out.print("sorry the book is not avalible, try again later");
                return quantity;
        // chang the quantity when costumer rturnes a book to the library
        public void deliverBookBack()
            quantity++;
        public String toString()
            return title + " by " + author + ". ISBN = " + ISBN ;
        // change the stock number after adding any book to the library
        public int autoStockNumber()
            stockNumber ++;
            return stockNumber;
        public int getStockNumber()
            return  stockNumber;
    }======================================================
    import java.util.ArrayList;
    import java.util.HashMap;
    public class library
        private ArrayList<books> book;
        private ArrayList<members> member;
      // i coudnt make the HashMap here.
        private HashMap<books , books> stock;   
        public library ()
            book = new ArrayList<books>();
            member = new ArrayList<members>();
            stock = new HashMap<books, books>();       
        // to add a book to the catalogue, for example when its newly published (the book information)
        public void newBook(books bk)
            book.add(bk);
        public void TheStateOfTheLibrary()
            //print the library name and address
            System.out.println("BlueJ Library: 10 College Lane, AL10 9BL");
            // print list of the books (title, author, ISBN)
            System.out.println("Catalogue :");
            for (books bk : book){
                System.out.println(bk);
            System.out.println("");
             * print stock list to show all stocks in the library
             *it should show:
             *stock number, books name, by : thuthor. ISBN
            System.out.println("Stock List:");
            System.out.println("");
            System.out.println("Membership List:");       
            for (members memb : member){
                System.out.println(memb);
        public void addMember(members memb)
            member.add(memb);
        // to add a copy of a book to it's stock, when the library receives this item.
        public void addBookToStock(books sn)
           // i coudnt make it
    }thank you

    actually im new in java and i dont really understand the HashMap.A HashMap is like an array except the index values of the array aren't integers. If you declare an array like this:
    int[] nums = new int[10];
    the index values of the array are the integers 0-9. To store something in the array, you do something like this:
    nums[0] = 3;
    0 is the index value and at that index position in the array is the integer 3.
    With a HashMap, you can use index values other than integers for your array. For instance, you can use Strings:
    index value           value stored at that index position in the array
    "John"                           "232-0416"
    "Sally"                          "451-0091"To add an index value to the map and store a value at that index position, you would do this:
    myMap.put("Jane", "456-7654");
    To get the telephone number at index position "John", you would do this:
    myMap.get("John");
    However, you have to do a little more work on the object returned by get(). When you add objects, like String objects, to one of java's collections, they are automatically converted to type Object first and then added to the collection. Then, when you retrieve objects from a collection, they are returned as type Object, so you need to cast them to their original type:
    String result = (String) myMap.get("John");
    That statement gets you whatever is stored at index position "John" in the array, which happens to be the String "232-0416". You don't have to make that cast in java 1.5 when you use generics, which is what you are doing.
    One last point: in HashMap lingo, the index values in the array are called "keys".
    i have an error " cannot find symbol- method put(int,books)You defined your HashMap like this:
    private HashMap<books , books> stock;
    That tells java that you are going to be using 'books' objects for the index values of the array, and that the values stored at those index positions will be 'books' objects. But here:
    public void addBookToStock(Books sn, Books b)
            int key = sn.getStockNumber();
            stock.put(key,  b);       // the error is in this line.
    }you are trying to use an int as the index value of the array. Since you told java you would be using "books" as index values, it produces an error.
    You should also rename your Books class to "Book". A Book object does not consist of several books--it represents only one book. If you had a collection containing a bunch of Book objects, then it would make sense to name the collection "Books".

  • Help needed with hashmap

    i have a class and declared some varaibales. In another class i am setting values for those variables.
    can i get the values of those variables into hashmap and iterate over those values
    if yes, can somebody pls tell me how to do that...
    for ex...
    class abc
    string x;
    string y;
    public String getx() {
    return x;
    public void setx(String x) {
    this.x = x;
    public String gety() {
    return y;
    public void sety(String y) {
    this.y = y;
    in another class
    class ABC
    abc a = new abc();
    a.setx("123")
    a.sety("xyz")
    now, i want to retreive those values(123 and xyz) and iterate over them ( in a hashmap) ,i.e convert them into objects and return them...
    pls tell me how to do that...
    thanks

    Mani_V wrote:
    can somebody explain with a sample code..pls1 Copy the link for the tutorial. Paste it into your browser.
    2 On the tutorial page, click on Interfaces
    3 On the Interfaces page, click on The Map Interface
    4 Just a little ways down the page, a HashMap example with explanation.

  • StackOverFlowError with Expression query

    We have an Expression query that will generate a query with 1500 to 2000 OR conditions based on some user input. The query does not return more than 2000 rows.
    We sometimes get a StackOverFlowError when the query is executed.
    We notice that the log has a call to printSQL multiple times -
    at oracle.toplink.internal.expressions.CompoundExpression.printSQL(CompoundExpression.java:216)
         at oracle.toplink.expressions.ExpressionOperator.printDuo(ExpressionOperator.java:1669)
    Any idea what is going on? Is there a limit on the SQL generated by Expression Query?
    Thanks for the help.
    LOG -
    java.lang.StackOverflowError
         at oracle.toplink.expressions.ExpressionOperator.printDuo(ExpressionOperator.java:1669)
         at oracle.toplink.internal.expressions.CompoundExpression.printSQL(CompoundExpression.java:216)
         at oracle.toplink.expressions.ExpressionOperator.printDuo(ExpressionOperator.java:1669)
         at oracle.toplink.internal.expressions.CompoundExpression.printSQL(CompoundExpression.java:216)
         at oracle.toplink.expressions.ExpressionOperator.printDuo(ExpressionOperator.java:1669)
    +. _(The above lines keep repeating multiple times)_+
         at oracle.toplink.internal.expressions.ExpressionSQLPrinter.translateExpression(ExpressionSQLPrinter.java:238)
         at oracle.toplink.internal.expressions.ExpressionSQLPrinter.printExpression(ExpressionSQLPrinter.java:106)
         at oracle.toplink.internal.expressions.SQLSelectStatement.printSQL(SQLSelectStatement.java:1199)
         at oracle.toplink.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:624)
         at oracle.toplink.publicinterface.Descriptor.buildCallFromStatement(Descriptor.java:558)
         at oracle.toplink.descriptors.ClassDescriptor.buildCallFromStatement(ClassDescriptor.java:191)
         at oracle.toplink.internal.queryframework.StatementQueryMechanism.setCallFromStatement(StatementQueryMechanism.java:381)
         at oracle.toplink.internal.queryframework.StatementQueryMechanism.prepareSelectAllRows(StatementQueryMechanism.java:307)
         at oracle.toplink.internal.queryframework.ExpressionQueryMechanism.prepareSelectAllRows(ExpressionQueryMechanism.java:685)
         at oracle.toplink.queryframework.ReadAllQuery.prepareSelectAllRows(ReadAllQuery.java:699)
         at oracle.toplink.queryframework.ReadAllQuery.prepare(ReadAllQuery.java:666)
         at oracle.toplink.queryframework.DatabaseQuery.checkPrepare(DatabaseQuery.java:405)
         at oracle.toplink.queryframework.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:554)
         at oracle.toplink.queryframework.DatabaseQuery.checkPrepare(DatabaseQuery.java:375)
         at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:598)
         at oracle.toplink.queryframework.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:781)
         at oracle.toplink.queryframework.ReadAllQuery.execute(ReadAllQuery.java:451)
         at oracle.toplink.publicinterface.Session.internalExecuteQuery(Session.java:2089)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:993)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:950)

    The query is building the SQL recursively from the expression. 2000 Or conditions seems fairly complex; if there is no way to pare down the complexity of the query you might try increasing the stack size.
    Best Regards,
    Chris

  • Help with HashMap!!!

    Hi all,
    My program reads the data from the external file called: "long.txt" which consists of a million records...
    The file is loaded into a list called: "HashMap list" and also store the keys into a separate array. Search is done in HashMap for all the key in the array or also known as an exhaustive search.
    I have the files: "long.txt", "HashMapTestnew.java" and "MyData.java" in the same directory called: "tmp"...
    Everything looks okay but when I try to compile this, I get the following error...
    HashMapTestnew.java:38: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTestnew
    MyData md = new MyData( sKey, Integer.parseInt(sVal) );
    ^
    HashMapTestnew.java:38: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTestnew
    MyData md = new MyData( sKey, Integer.parseInt(sVal) );
    ^
    HashMapTestnew.java:55: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTestnew
    MyData md;
    ^
    HashMapTestnew.java:66: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTestnew
    md = (MyData) me.getValue();
    ^
    4 errors
    Tool completed with exit code 1
    import java.util.*;
    import java.io.*;
    public class HashMapTestnew
    public static HashMap getMapList()
         String MyData;
         Int sKey;
    String strLine;
    HashMap hm = new HashMap();
    try
    BufferedReader fBR = new BufferedReader( new FileReader("long.txt") );
    while ( fBR.ready() )
    strLine = fBR.readLine();
    if (strLine != null)
    StringTokenizer st = new StringTokenizer(strLine, "\t");
    String sKey = st.nextToken();
    String sVal = st.nextToken();
    MyData md = new MyData( sKey, Integer.parseInt(sVal) );
    hm.put(sKey, md);
    fBR.close();
    catch (IOException ioe)
    System.out.println("I/O Trouble ...");
    return hm;
    public static void showMapList(HashMap hashMap, int n)
    String strVal;
    String strNdx;
    MyData md;
    System.out.println("\nHashMap List (first 10 records):");
    Map.Entry me;
    Set shm = hashMap.entrySet();
    Iterator j = shm.iterator();
    int i = 0;
    while (j.hasNext() && (i++)< n)
    me = (Map.Entry) j.next();
    strVal = (String) me.getKey();
    md = (MyData) me.getValue();
    System.out.println(i + ": " + md.getVal() + "\t" + md.getNdx() );
    public static String[] getKeys(HashMap hashMap)
    String[] key = new String[hashMap.size()];
    Map.Entry me;
    Set shm = hashMap.entrySet();
    Iterator j = shm.iterator();
    int i = 0;
    while (j.hasNext())
    me = (Map.Entry) j.next();
    key[i] = (String) me.getKey();
    i++;
    return key;
    public static void searchMapList(HashMap hashMap, String[] key)
    int i,n=0;
    System.out.println("Search Started:");
    long tim1 = System.currentTimeMillis();
    for (i=0; i<key.length; i++)
    if (hashMap.containsKey(key))
    n++;
    long tim2 = System.currentTimeMillis();
    System.out.println("Search Ended After " + (tim2-tim1) + " miliseconds.");
    System.out.println("Searched for " + key.length + " keys.");
    System.out.println("Found " + n + " keys.");
    public static void main(String[] arg)
    HashMap hashMap = getMapList(); // Create the hash map list
    showMapList(hashMap, 10); // Display part of the hash map list
    String[] searchKey = getKeys(hashMap); // an array of all search keys
    searchMapList(hashMap, searchKey); // Search for all existing keys in the list
    Can anybody help me with this?
    I'm new to Java... What does the error message: "cannot resolve symbol
    symbol : class MyData" mean???
    P.S. When I compiled the file "MyData.java", it compiles without any error...
    Thanks,
    Lilian

    I moved the 3 files ("MyData.java", "long txt" and "HashMapTest.java") to a directory called "MyData" as well as added the code: "package MyData;"
    before the codes:
    import java.util.*;
    import java.io.*;
    just to see if it would make any difference but I still got the following error messages:
    C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:38: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTest
    MyData md = new MyData( sKey, Integer.parseInt(sVal) );
    ^
    C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:38: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTest
    MyData md = new MyData( sKey, Integer.parseInt(sVal) );
    ^
    C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:55: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTest
    MyData md;
    ^
    C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:66: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTest
    md = (MyData) me.getValue();
    ^
    4 errors
    Tool completed with exit code 1
    By the way, I'm compiling the java program using a Textpad editor and selecting Tools -->> Compile Java...
    Let me know if you have any questions...
    Thanks,
    Lilian
    location: class MyData.HashMapTestnewThis says that you have declared your HashMapTestnew
    class to be in package MyData.
    I have the files: "long.txt", "HashMapTestnew.java"and "MyData.java" in the same directory called:
    "tmp"...
    If you want HashMapTestnew to be in package MyData,
    then it should have been in a directory called MyData.
    But having a class with the same name as a package is
    very confusing, so I don't think you should do that.
    In fact, since you are new to Java I don't think you
    u should use packages at all until you can compile
    non-packaged classes correctly.
    I'm surprised I don't see the line "package MyData" at
    the top of the code you posted. But then I'm not
    surprised, because since your class isn't in the right
    directory for that package, you should have got
    different error messages. What exactly did you type
    at the command line to compile the class?

  • Help with HashMap and Collections

    Hey everyone,
    I am currently writing a program that makes use of HashMap, which I am not at all familiar with. I looked it up in some books and some websites, but it seems everyone does something different every time so I need some guidance. My program is to take Inventory Item objects that have an name and an inventory number and store them in a HashMap. Originally I had them stored in an Array but now it's gonna be in a HashMap. This also uses some Java GUI elements so bear with me.
    Ok, first here is my code for my Item object:
    public class Item{
        private String number;
        private String name;
        public Item(String number, String name) {
              this.number = number;
              this.name = name;
          @Override
          public String toString() {
              return "#"+number+"  N:"+name;
    }And this is what I got so far for my Inventory GUI:
    import java.util.HashMap;
    import java.util.Iterator;
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.Label;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.JScrollPane;
    public class InventoryGUI {
         //private static Item[] item = new Item[10];
         HashMap hash = new HashMap();
         private static int count = 0;
         public static void main(String[] args) {
              JFrame gui = new JFrame("Project 2 GUI");
              gui.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              JPanel inputPanel = new JPanel();
              inputPanel.setLayout(new GridLayout(5,2));
              inputPanel.add(new Label("Inventory Number"));
              final JTextField numberField = new JTextField(15);
              inputPanel.add(numberField);
              inputPanel.add(new Label("Name"));
              final JTextField nameField = new JTextField(15);
              inputPanel.add(nameField);
              gui.add(inputPanel, BorderLayout.NORTH);
              final DefaultListModel dfl = new DefaultListModel();
              JList jl = new JList(dfl);
              JScrollPane jsp = new JScrollPane(jl);
              gui.add(jsp);
              JPanel southPanel = new JPanel();
              southPanel.setLayout(new GridLayout(2,1));
              final JTextField errorMsg = new JTextField();
              errorMsg.setEditable(false);
              southPanel.add(errorMsg);
              JPanel buttonPanel = new JPanel();
              southPanel.add(buttonPanel);
              JButton addButton = new JButton("Add");
              addButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        String number = numberField.getText();
                          numberField.setText("");
                         String name = nameField.getText();
                          nameField.setText("");
                               hash.put(number, name);
                               count++;
              buttonPanel.add(addButton);
              JButton deleteButton = new JButton("Delete");
              deleteButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
              buttonPanel.add(deleteButton);
              JButton findButton = new JButton("Find");
              findButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        dfl.clear();
                        String temp = hashMap.get(number);
                              dfl.addElement(temp);
              buttonPanel.add(findButton);
              JButton showButton = new JButton("Show");
              showButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        dfl.clear();
                          for (Item p : item) {
                              dfl.addElement(p);
              buttonPanel.add(showButton);
              JButton saveButton = new JButton("Save");
              saveButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
              buttonPanel.add(saveButton);
              JButton restoreButton = new JButton("Restore");
              restoreButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
              buttonPanel.add(restoreButton);
              JButton exitButton = new JButton("Exit");
              exitButton.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        System.exit(1);
              buttonPanel.add(exitButton);
              gui.add(southPanel, BorderLayout.SOUTH);
              gui.pack();
              gui.setVisible(true);
    }I know a lot of those buttons are missing functions, but I want to get clear on how to implement a HashMap here. Any help or insight will be greatly appreciated.

    Hey thanks for that, it was some nice insight. However I'm still stumped on how HashMap needs to work in this situation. It worked fine with an object array, but this is stumping me good. To be a little more specific, I need several functions to happen with this HashMap, each correlating with a button for the GUI.
    It needs to be able to add Item objects to the HashMap (the key is the inventory number, and the value is the Item object), it needs to be able to delete an Item object (by using the inventory number), it needs to be able to find Items by inventory number, show all Items currently in the HashMap, save the info in the HashMap to a file on disk by using ObjectStreams, and a restore button just loads the data from that file to the HashMap.
    It's a lot right? :D
    I'm struggling to get anything to work with a HashMap however. If I could get some assistance with any of these functions, I would greatly appreciate it. Here's my updated code:
    import java.util.HashMap;
    import java.util.Iterator;
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.Label;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.JScrollPane;
    public class InventoryGUI {
         //private static Item[] item = new Item[10];
         HashMap hash = new HashMap();
         private static int count = 0;
         public static void main(String[] args) {
              JFrame gui = new JFrame("Project 2 GUI");
              gui.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              JPanel inputPanel = new JPanel();
              inputPanel.setLayout(new GridLayout(5,2));
              inputPanel.add(new Label("Inventory Number"));
              final JTextField numberField = new JTextField(15);
              inputPanel.add(numberField);
              inputPanel.add(new Label("Name"));
              final JTextField nameField = new JTextField(15);
              inputPanel.add(nameField);
              inputPanel.add(new Label("Manufacturer"));
              final JTextField manField = new JTextField(15);
              inputPanel.add(manField);
              inputPanel.add(new Label("Description"));
              final JTextField descField = new JTextField(15);
              inputPanel.add(descField);
              inputPanel.add(new Label("Price"));
              final JTextField priceField = new JTextField(15);
              inputPanel.add(priceField);
              gui.add(inputPanel, BorderLayout.NORTH);
              final DefaultListModel dfl = new DefaultListModel();
              JList jl = new JList(dfl);
              JScrollPane jsp = new JScrollPane(jl);
              gui.add(jsp);
              JPanel southPanel = new JPanel();
              southPanel.setLayout(new GridLayout(2,1));
              final JTextField errorMsg = new JTextField();
              errorMsg.setEditable(false);
              southPanel.add(errorMsg);
              JPanel buttonPanel = new JPanel();
              southPanel.add(buttonPanel);
              JButton addButton = new JButton("Add");
              addButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        String number = numberField.getText();
                          numberField.setText("");
                         String name = nameField.getText();
                          nameField.setText("");
                         String manufacturer = manField.getText();
                          manField.setText("");
                         String description = descField.getText();
                          descField.setText("");
                         float price = Integer.parseInt(priceField.getText());
                          priceField.setText("");
                             Item myItem=new Item(number, name, manufacturer, description, price);
                               hash.put(number, myItem);
                               count++;
              buttonPanel.add(addButton);
              JButton deleteButton = new JButton("Delete");
              deleteButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                   dfl.clear();
                   String number = numberField.getText();
                    numberField.setText("");
                   hashMap.remove(number);
              buttonPanel.add(deleteButton);
              JButton findButton = new JButton("Find");
              findButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        dfl.clear();
                        String number = numberField.getText();
                           numberField.setText("");
                        Item temp = new Item(hashMap.get(number));
                              dfl.addElement(temp);
              buttonPanel.add(findButton);
              JButton showButton = new JButton("Show");
              showButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        dfl.clear();
                          for (Item p : item) {
                              dfl.addElement(p);
              buttonPanel.add(showButton);
              JButton saveButton = new JButton("Save");
              saveButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
              buttonPanel.add(saveButton);
              JButton restoreButton = new JButton("Restore");
              restoreButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
              buttonPanel.add(restoreButton);
              JButton exitButton = new JButton("Exit");
              exitButton.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        System.exit(1);
              buttonPanel.add(exitButton);
              gui.add(southPanel, BorderLayout.SOUTH);
              gui.pack();
              gui.setVisible(true);
    }Thanks for any help you can give me!

  • StackOverflowError with a JDOException

    Hi,
    I'm getting a StackOverflowError when I catch a JDOException and try and
    print it. The Kodo tutorial app throwing a kodo.util.UserException, but
    when I try to print the stack trace it gets into an endless loop and I get
    a java.lang.StackOverflowError. This is some of the stack trace (bear in
    mind it is infinite):
    Exception in thread "main" java.lang.StackOverflowError
    at java.lang.Exception.<init>(Exception.java:33)
    at java.lang.RuntimeException.<init>(RuntimeException.java:38)
    at javax.jdo.JDOException.<init>(Unknown Source)
    at javax.jdo.JDOCanRetryException.<init>(Unknown Source)
    at javax.jdo.JDOUserException.<init>(Unknown Source)
    at kodo.util.UserException.<init>(UserException.java:50)
    at kodo.util.UserException.<init>(UserException.java:31)
    at kodo.runtime.JDOState.error(JDOState.java:407)
    at
    kodo.runtime.PDeletedState.beforeOptimisticRead(PDeletedState.java:79
    at
    kodo.runtime.StateManagerImpl.isLoaded(StateManagerImpl.java:980)
    at tutorial.Animal.jdoGetname(Animal.java)
    at tutorial.Animal.getName(Animal.java:31)
    at tutorial.Dog.toString(Dog.java:20)
    at tutorial.Animal.toString(Animal.java:49)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    ..and so on.
    The toString method of JDOException does a toString on the associated
    persistent object, but in this case the persistent object has been
    deleted, so the read from the database fails...
    This is not good, because printing an exception should NEVER cause another
    exception to be thrown. Exceptions should be caught if the associated
    persistent object cannot be printed. My question is: is this a bug in
    Sun's JDO code, and could Kodo be modified
    [kodo.util.UserException.toString() ?] to avoid this nasty situation?
    Regards,
    Alex

    Alex,
    Based on your description, it sounds like you have invoked
    deletePersistent() on the object in question. So, the "Operation attempted
    on a deleted instance" exception is expected when you try to access the
    object.
    So, it sounds like the following is happening:
    - invoke deletePersistent() on an object
    - attempt to print the deleted object
    - access a persistent field. Because the object has been deleted,
    the persistent state has been cleared, and an exception is thrown
    when the field is accessed (this is the "Operation attempted on a
    deleted instance" exception).
    - catch the exception
    - attempt to print out the exception, which evidently is invoking
    toString() on the object, which is causing an exception...
    Does this make sense? So, either making toString() not access persistent
    fields, or printing out the object before deleting it, should fix the
    problem.
    -Patrick
    Since calling toString() is in turn accessing a persistent field,
    On Tue, 14 Oct 2003 17:09:43 +0000, Alex Robbins wrote:
    Sure,
    I'm not doing anything clever, just running the tutorial app, with just 1
    change made to it: I moved lines 83-84 of AnimalMaintenance to after the
    call to pm.deletePersistentAll(objects) (line 87) so that it only prints
    out the message if it successfully deleted the objects. This seems to have
    broken the app. I've put it back to how it was, and it works fine.
    This is a bit concerning, as I would have expected the toString method to
    be indempotent (have no side effects), but you get diff behaviour if you
    call the toString method. In the Java source, toString calls
    Animal.getName which just returns the name member variable. BUT the
    bytecode has been "enhanced" so that it is probably doing jdo stuff like
    accessing the DB when you access the field. Somehow accessing the field
    puts the object into a valid state, from where it can be deleted. But if
    you try to delete it without doing a read, it fails with a
    kodo.util.UserException, with the message "Operation attempted on a
    deleted instance". I swear I have not deleted it - it is there in the DB.
    To get the stack overflow, I just put a catch block into the main method
    with prints e.toString() to stderr or does a e.printStackTrace() - either
    causes the overflow. e.getMessage() is okay though. Looking in Sun's JDO
    src, it is clear tha JDOException's toString does a toString on the
    'failed' object, i.e. my poor Dog:
    public String toString() {
    int len = nested==null?0:nested.length;
    // calculate approximate size of the String to return
    StringBuffer sb = new StringBuffer (10 + 100 * len);
    sb.append (super.toString());
    // include failed object information
    if (failed != null) {
    sb.append (MSG_FAILED_OBJECT);
    String failedToString = null;
    try {
    failedToString = failed.toString();
    } catch (Exception ex) {
    failedToString = msg.msg("MSG_ExceptionGettingFailedToString",
    ex.toString()); //NOI18N
    sb.append (failedToString);
    // include nested Throwable information
    if (len > 0) {
    sb.append (MSG_NESTED_THROWABLES);
    Throwable exception = nested[0];
    sb.append (exception==null?"null":exception.toString()); //NOI18N
    for (int i=1; i<len; ++i) {
    sb.append ("\n"); //NOI18N
    exception = nested;
    sb.append (exception==null?"null":exception.toString()); //NOI18N
    return sb.toString();
    .and the toString on the Dog does some DB access which fails,
    recursively, leading to a stack overflow. Nasty, huh?
    Alex.
    Stephen Kim wrote:
    Hmm, are you calling a printStackTrace ()? Can you post the code you
    are using to generate and parse the exception?
    Alex Robbins wrote:
    Hi,
    I'm getting a StackOverflowError when I catch a JDOException and try and
    print it. The Kodo tutorial app throwing a kodo.util.UserException, but
    when I try to print the stack trace it gets into an endless loop and I get
    a java.lang.StackOverflowError. This is some of the stack trace (bear in
    mind it is infinite):
    Exception in thread "main" java.lang.StackOverflowError
    at java.lang.Exception.<init>(Exception.java:33)
    at java.lang.RuntimeException.<init>(RuntimeException.java:38)
    at javax.jdo.JDOException.<init>(Unknown Source)
    at javax.jdo.JDOCanRetryException.<init>(Unknown Source)
    at javax.jdo.JDOUserException.<init>(Unknown Source)
    at kodo.util.UserException.<init>(UserException.java:50)
    at kodo.util.UserException.<init>(UserException.java:31)
    at kodo.runtime.JDOState.error(JDOState.java:407)
    at
    kodo.runtime.PDeletedState.beforeOptimisticRead(PDeletedState.java:79
    at
    kodo.runtime.StateManagerImpl.isLoaded(StateManagerImpl.java:980)
    at tutorial.Animal.jdoGetname(Animal.java)
    at tutorial.Animal.getName(Animal.java:31)
    at tutorial.Dog.toString(Dog.java:20)
    at tutorial.Animal.toString(Animal.java:49)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    at javax.jdo.JDOException.toString(Unknown Source)
    .and so on.
    The toString method of JDOException does a toString on the associated
    persistent object, but in this case the persistent object has been
    deleted, so the read from the database fails...
    This is not good, because printing an exception should NEVER cause another
    exception to be thrown. Exceptions should be caught if the associated
    persistent object cannot be printed. My question is: is this a bug in
    Sun's JDO code, and could Kodo be modified
    [kodo.util.UserException.toString() ?] to avoid this nasty situation?
    Regards,
    Alex
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com
    Patrick Linskey
    SolarMetric Inc.

  • Having Problems with Hashmap

    Hi, I'm currently creating a sparsematrix for my assignment using a hash map however i've come across a problem with how i can set an element and returning using key objects
    My setElement method is
    public void setElement(int nrow, int ncol, float value) throws
    MatrixException {
    data.put(new SparseNode(nrow,ncol), value);
    and my get element is
    public float getElement(int row, int col) throws MatrixException {
    SparseNode node = new SparseNode(row, col);
              if (!data.containsKey(node)) {
              return 0;
    return (Float) data.get(node);
    where data is the map and node would be the key. The problem comes when i set the value where i give a key and this is set into the hashmap. unfortunatly the key is lost when the method exits so using the getElement method by creating a sparsenode with same characteristics as the original key won't work simply because it's not the original key. Is there another way to get around this? or some way to store the key.

    ok well i changed to to not include the SparseNode. Now it works but very very slow. I also noticed another post with a user with the same problem but it didn't really explain how to fix it properly. Any suggestions to make this code faster?
    import java.io.*;
    import java.util.*;
    public class SparseMatrix implements Matrix{
        private HashMap data; // non zero elements
         private int rows;
         private int columns;
        public SparseMatrix(int row, int columns) {
            data = new HashMap(row*columns);
            this.rows=row;
            this.columns=columns;
        public float getElement(int row, int col) throws MatrixException {
                if (row < 0 || col < 0 || row > this.getNumRows() || col > this.getNumCols()) {
                throw new MatrixException("Row or Column Number Beyond Dimension");
                     if (!data.containsKey((row*this.getNumCols()+col))) {
                        return 0;
            return (Float) data.get((row*this.getNumCols()+col));
        public void setElement(int nrow, int ncol, float value) throws MatrixException {
    //        if (row > this.row || col > this.col) {
    //           throw new MatrixException("Matrix index out of range");
            data.put((nrow*this.getNumCols()+ncol), new Float(value));
        public boolean isZero() {
            return data.isEmpty();
        // return the total number of rows in the matrix
       public int getNumRows(){
            return rows;
       // return the total number of rows in the matrix
       public int getNumCols(){
            return this.columns;
       // transpose matrix and return result as new matrix
        public Matrix transpose() {
            SparseMatrix a = new SparseMatrix(this.getNumCols(), this.getNumRows());
            for (int i =1 ; i<=this.getNumRows();i++) {
                for (int j = 1;j<=this.getNumCols();j++){
                      float value = getElement(i,j);
                     a.setElement(j, i, value );
            return a;
        * Subtracts a matrix to the current matrix and returns result as new matrix
        * @param a The Matrix to be subtracted
        * @return Returns the new matrix
       public Matrix subtract(Matrix a) throws MatrixException{
                 if (this.getNumRows() != a.getNumRows() || this.getNumCols() != a.getNumCols())
                    throw new MatrixException("Subtraction Cannot be Done due to Matrix Dimension MisMatch");
                if (a.isZero())
                    return this;
                    SparseMatrix ResultMatrix = new SparseMatrix(this.getNumRows(), this.getNumCols());
            for (int i = 1; i <= rows; i++) {
                for (int j = 1; j <= columns; j++) {          
                     float value = a.getElement(i,j);
                     float result = this.getElement(i,j) - value;
                     if (result < 0 || result > 0) {
                         ResultMatrix.setElement(i,j,result);
                 return ResultMatrix;
        // add matrix and return result as new matrix
        public Matrix add(Matrix a) throws MatrixException {
                if (this.getNumRows()!= a.getNumRows() || this.getNumCols()!= a.getNumCols())
                throw new MatrixException("Addition Cannot be Done due to Matrix Dimension MisMatch");
            if (this.isZero())
                return a;
            if (a.isZero())
                return this;
                SparseMatrix ResultMatrix = new SparseMatrix(this.getNumRows(), this.getNumCols());
            for (int i = 1; i <= rows; i++) {
                for (int j = 1; j <= columns; j++) {          
                     float value = a.getElement(i,j);
                     float result = this.getElement(i,j) + value;
                     if (result < 0 || result > 0) {
                         ResultMatrix.setElement(i,j,result);
                 return ResultMatrix;
    // multiply matrix and return result as new matrix
         public Matrix multiply(Matrix a) throws MatrixException {
                              if (this.getNumCols() != a.getNumRows())
                throw new MatrixException("Multiplication Cannot be Done due to Matrix Dimension MisMatch");
            if (this.isZero() || a.isZero())
                SparseMatrix Temp = new SparseMatrix(this.getNumRows(), a.getNumCols());
                return Temp;
             SparseMatrix ResultMatrix = new SparseMatrix(this.getNumRows(), this.getNumCols());
              for(int i=1;i<=this.getNumRows();i++)
                   for(int j=1;j<=a.getNumCols();j++)
                                  float Result =0;
                                  for(int k=1;k<a.getNumCols();k++)
                                       Result = Result + this.getElement(i,k)*a.getElement(k,j);
                                  ResultMatrix.setElement(i,j,Result);
              return ResultMatrix;
         // print matrix in the format:
       // a11 a12 ... a1m
       // an1 an2 ... anm
        public void print(PrintStream out) {
             //System.out.println(data.toString() +"\n=====================");
            for (int i = 1; i <= this.getNumRows(); i++) {
                for (int j = 1; j <= this.getNumCols(); j++) {
                    float aData = this.getElement(i, j);
                    out.print(" " + aData + "");
                out.println();
    }

  • Help needed with hashmaps

    Hi friends,
    I am new to java programming and I have learnt a lot from this forum. Hope you find out what's wrong with the following program:
    the error message says
    "Cannot find symbol
    Symbol : method put()
    Location : ids520.HashMap"
    package ids520;
    import java.util.*;
    public class UserHashMap {
         private HashMap hashMap;
         public UserHashMap()
                 HashMap hashMap = new HashMap();
              hashMap.put("user1", "easy11");           //Program shows errors here saying "Cannot find symbol                  
              hashMap.put("user2", "easy21");           // Symbol : method put()
              hashMap.put("user3", "easy31");           // Location : ids520.UserHashMap
         public HashMap getHashMap() {
              return hashMap;
         public void setHashMap(HashMap hashMap) {
              this.hashMap = hashMap;
    }{code}{code}{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    This is one of the programs..
    package chatServer;
    import ids520.UserHashMap;
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    //import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class MultiThreadServer extends JFrame{
        private JTextArea taServerState;
        public static void main(String[] args) {
            new MultiThreadServer();
        public MultiThreadServer() {
            getContentPane().setLayout(new BorderLayout());
            getContentPane().add(taServerState = new JTextArea(450,250));
            getContentPane().add(new JScrollPane(taServerState), BorderLayout.CENTER);
            taServerState.setEditable(false);
            setTitle("MultiThread Server");
            setSize(500, 300);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
            try {
                ServerSocket serverSocket = new ServerSocket(8000);
                taServerState.append("MultiThreadServer started at " + new Date() + '\n');
                int clientNo = 1;
                while(true) {
                    Socket connectToClient = serverSocket.accept();
                    taServerState.append("Starting thread client " + clientNo + " at" + new Date() + '\n');
                    InetAddress clientInetAddress = connectToClient.getInetAddress();
                    taServerState.append("Client " + clientNo + "'s hostname is " + clientInetAddress.getHostName() + "\n");
                    taServerState.append("Client " + clientNo + "'s hostaddress is " + clientInetAddress.getHostAddress() + "\n");
                    HandleAClient thread = new HandleAClient(connectToClient);
                    thread.start();
            } catch(IOException ex) {
                System.err.println("Error occured: " + ex);
        class HandleAClient extends Thread {
            private Socket connectToClient;
            public HandleAClient(Socket socket) {
                connectToClient = socket;
            public void run() {
                String loginStatus;
                try {
                    DataInputStream isFromClient = new DataInputStream(connectToClient.getInputStream());
                    DataOutputStream osToClient = new DataOutputStream(connectToClient.getOutputStream());
                    while(true) {
                        String ipPacket = isFromClient.readUTF();
                        String []pcktParts = ipPacket.split(":");
                        String message = pcktParts[0];
                        String msgType = pcktParts[1];
                        String to = pcktParts[2];
                        String from = pcktParts[3];
                        if(msgType.equals("login")) {
                            String []loginInfo = message.split(";");
                            String username = loginInfo[0];
                            String password = loginInfo[1];
                            UserHashMap usermap = new UserHashMap();
                            HashMap userMap1;
                             userMap1 = usermap.getHashMap();
                            taServerState.append("User with username" + username + "trying to login");
                            if(((String)userMap1.get(username)).equals(password)) {
                                loginStatus = "pass";
                                taServerState.append("Login is authenticated");
                            } else {
                                loginStatus = "fail";
                                taServerState.append("User not authenticated, username or password could be wrong");
                            osToClient.writeChars(loginStatus);
                } catch(IOException e) {
                    System.err.println("Error Encountered: "+ e);
    }

  • Simple Problem with hashmap

    Hello,
    I am having a problem creating a hashmap--I am not sure what is going wrong, but here is the code I am using:
    import java.util.*;
    public class HashMap{
    public static void main(String args[]){
         HashMap myHashMap = new HashMap();
         myHashMap.put("one","1");
    When I go to compile I get this error:
    HashMap.java:6: cannot resolve symbol
    symbol : method put (java.lang.String,java.lang.String)
    location class HashMap
    myHashMap.put("one","1");
    ^
    If anyone could offer some help that would be great. Thanks!

    THANK YOU!
    I'm a newbie and this problem was driving me crazy also. I inadvertently created a HashMap.class. Once I deleted the class from the folder, all of my programs worked! (Duh!)

Maybe you are looking for

  • I am not able to send email using JAVA API to outer email

    If I am trying to send email from my company account to yahoo I am getting following errors: javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email pr

  • Reg:Time excel file missing in BPC 7.5

    Hi Experts, 1.I am trying to change the data model of time dimesion in APSHELL but i cannot find the file in the below mentioned path. eData > Manage Conversion File > Examples > TIME.xls 2. How to change the Unit of measure data model? Regards, Vino

  • Best Way to Aggregate Multiple Announcement Apps and Possibly External RSS Feed

    Hello, I have two separate announcement apps (one in sub-site A, and one is sub-site B). I am trying to create a webpart that will display content from both apps together. I have tried to setup a CSWP and have been able to set the query to pull in th

  • CS5.5 Install - Volume Licensing - What file to I install first?

    I downloaded my installation instructions for CS5.5 upgrade from the volume license website at licensing.adobe.com.     I was presented with five files to download. 1. Adobe CS5.5 Installation Instructions. This is a .pdf file 2. Adobe Web Premium CS

  • New xine-ui package's lirc support broken?

    Hi, the abs pkgbuild for xine-ui shows the --enable-lirc flag being set but still I had to recompile that package to get lirc with xine working? Anyone else experiencing that problem too? If I'm not the only one I would post it on flyspray (well or a