-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: java.lang.IndexOutOfBoundsException when getting data out
PostPosted: Mon Sep 06, 2004 4:44 am 
Newbie

Joined: Sun Aug 08, 2004 2:38 am
Posts: 9
Hibernate version:2.1.6

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:mysql

Debug level Hibernate log excerpt:

Hello,
I use Hibernate 2.1.6 to get data out from the database. My database has two tables, first, I want get the 'moduleNo' from one table, and use the 'moduleNo' fetched to query another table and get the 'userName' sector in a string array. The code is as follows:

Code:
users[i] = (userinfo)((operateDB.queryUserinfoByModuleNo(strModuleNo[i])).get(i));
When running the program, it also be a
Quote:
java.lang.IndexOutOfBoundsException
. Please help!

Thanks:)

Regards,

_________________
THINK!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 4:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Full stack trace of any exception that occurs:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 7:30 am 
Newbie

Joined: Sun Aug 08, 2004 2:38 am
Posts: 9
The stack trace is as below, Thanks for help!

Quote:
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0

at java.util.ArrayList.RangeCheck(ArrayList.java:507)

at java.util.ArrayList.get(ArrayList.java:324)

at gui.MainFrame_ElecBox.getUserName(MainFrame_ElecBox.java:109)

at gui.MainFrame_ElecBox.<init>(MainFrame_ElecBox.java:38)

at gui.MainFrame.jMenuElecCtrl_Query_actionPerformed(MainFrame.java:243)

at gui.MainFrame_jMenuElecCtrl_Query_actionAdapter.actionPerformed(MainFrame.java:362)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.AbstractButton.doClick(AbstractButton.java:289)

at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113)

at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

_________________
THINK!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 11:54 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
there is no hibernate code in your stack trace.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 12:11 am 
Newbie

Joined: Sun Aug 08, 2004 2:38 am
Posts: 9
Sorry, That is my running log:
Quote:
12:07:18,581 INFO Configuration:350 - Mapping resource: database/userinfo.hbm.xml

12:07:18,681 INFO Binder:229 - Mapping class: database.userinfo -> userinfo

12:07:18,681 INFO Configuration:627 - processing one-to-many association mappings

12:07:18,681 INFO Configuration:636 - processing one-to-one association property references

12:07:18,681 INFO Configuration:661 - processing foreign key constraints

12:07:18,681 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.MySQLDialect

12:07:18,691 INFO SettingsFactory:59 - Maximim outer join fetch depth: 1

12:07:18,691 INFO SettingsFactory:63 - Use outer join fetching: true

12:07:18,691 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!)

12:07:18,691 INFO DriverManagerConnectionProvider:43 - Hibernate connection pool size: 1

12:07:18,691 INFO DriverManagerConnectionProvider:77 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql:///ElecCtrl

12:07:18,691 INFO DriverManagerConnectionProvider:78 - connection properties: {user=root, password=}

12:07:18,691 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)

12:07:18,721 INFO SettingsFactory:103 - Use scrollable result sets: true

12:07:18,721 INFO SettingsFactory:106 - Use JDBC3 getGeneratedKeys(): true

12:07:18,721 INFO SettingsFactory:109 - Optimize cache for minimal puts: false

12:07:18,721 INFO SettingsFactory:118 - Query language substitutions: {no='N', true=1, yes='Y', false=0}

12:07:18,721 INFO SettingsFactory:129 - cache provider: net.sf.hibernate.cache.EhCacheProvider

12:07:18,721 INFO SettingsFactory:141 - query cache factory: net.sf.hibernate.cache.StandardQueryCacheFactory

12:07:18,721 INFO Configuration:1116 - instantiating and configuring caches

12:07:18,721 INFO SessionFactoryImpl:118 - building session factory

12:07:18,781 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured

12:07:18,781 INFO UpdateTimestampsCache:35 - starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache

12:07:18,781 INFO StandardQueryCache:41 - starting query cache at region: net.sf.hibernate.cache.StandardQueryCache

java.lang.IndexOutOfBoundsException: Index: 1, Size: 0

at java.util.ArrayList.RangeCheck(ArrayList.java:507)

at java.util.ArrayList.get(ArrayList.java:324)

at gui.MainFrame_ElecBox.getUserName(MainFrame_ElecBox.java:110)

at gui.MainFrame_ElecBox.<init>(MainFrame_ElecBox.java:38)

at gui.MainFrame.jMenuElecCtrl_Query_actionPerformed(MainFrame.java:243)

at gui.MainFrame_jMenuElecCtrl_Query_actionAdapter.actionPerformed(MainFrame.java:362)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.AbstractButton.doClick(AbstractButton.java:289)

at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113)

at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)


The code of the error class is as below:
Code:
/*
* MainFrame_ElecBox.java
* Copyright(c) 2004   All Rights Reserved.
* Programmed by George Ren 2004-9-3
*/

package gui;

import java.awt.*;
import javax.swing.*;
import database.*;

/**
* <p>Title:</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: Nanjing Univ. of Posts & Telecommunications</p>
* @author George Ren
* @version 1.0
*/



/**
* This class is a JDialog object which displays when Electric Control | Query
* is clicked.
* <p>Title: Remote Electricity Control and Allocate</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: Nanjing Univ. of Posts & Telecommunications</p>
* @author George Ren
* @version 1.0
*/
public class MainFrame_ElecBox extends JDialog {
  JPanel panel1 = new JPanel();
  JLabel jLabel1 = new JLabel();
  private OperateDB operateDB = new OperateDB();
  JComboBox jComboBox_Users = new JComboBox(getUserName());
  private String strUserName[];
  private String strModuleNo[];
  private java.util.List listElecDatas;
  private java.util.List listUserNames;
  private Dimension dim = new Dimension(399,299);
  private userinfo users[];

  /**
   * The constructor with a parameter
   * @param frame Frame the container used to contain this JDialog object
   */
  public MainFrame_ElecBox(Frame frame) {
    super(frame);
    try {
      jbInit();
      pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }


  /**
   * The default non-parameter constructor
   */
  public MainFrame_ElecBox() {
    this(null);
  }


  /**
   * Initialize the components
   * @throws Exception when something is wrong during initialization
   */
  private void jbInit() throws Exception {

    panel1.setLayout(null);
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
    jLabel1.setText("Select user you want");
    jLabel1.setBounds(new Rectangle(25, 24, 166, 35));
    jComboBox_Users.setFont(new java.awt.Font("Dialog", 0, 12));
    jComboBox_Users.setBounds(new Rectangle(168, 28, 196, 27));
    getContentPane().add(panel1);
    panel1.add(jLabel1, null);
    panel1.add(jComboBox_Users, null);
    panel1.setPreferredSize(dim);
    this.setSize(dim);
  }


  /**
   * This method fetch out all of the records in the elecdata table at first, and
   * use these records' module number to query the userinfo table and fetch out
   * all records those have the same module number, and pass these records' uesrName
   * to a JComboBox object as its items.
   * @return String[] the user names which are to display in a JComboBox object
   * as items
   */
  private String[] getUserName(){
    listElecDatas = operateDB.listAll("elecdata");
    strUserName = new String[listElecDatas.size()];
    strModuleNo = new String[listElecDatas.size()];
    users = new userinfo[listElecDatas.size()];
    System.out.println(users.length);

    //fetch the module number of the records in the elecdata table
    for(int i = 0; i<listElecDatas.size(); i++){
      strModuleNo[i] = ((elecdata)listElecDatas.get(i)).getModuleNo();
      //listUserNames.add(i, (operateDB.queryUserinfoByModuleNo(strModuleNo[i])).get(0));
      System.out.println("**********************************");
      [b]users[i] = (userinfo)((operateDB.queryUserinfoByModuleNo(strModuleNo[i])).get(i));[/b]   
}
    for(int  i = 0, k = 0; k<users.length; k++, i++){
      //get the module number in a list and pass them in a object array

    }

    //use the module number to query userinfo table and fetch the correspoding
    //records out.
    for(int j = 0; j<users.length; j++){
      strUserName[j] = ((userinfo)users[j]).getUserName();
    }
    return strUserName;
  }
}



The highlighted line of code cause the error.

Thanks for help!

Have a nice day!

_________________
THINK!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 2:19 am 
Regular
Regular

Joined: Thu Aug 05, 2004 2:27 am
Posts: 54
Location: South Africa
Quote:
The highlighted line of code cause the error.


actually according to the stacktrace
Code:
strUserName[j] = ((userinfo)users[j]).getUserName();
causes the error.

basically you've initialised the array, and then tried to populate it, trouble is I don't think it was successful.
so to fix this first check that you actually have a "userinfo" object to put into the array.
If you still can't figure it out feel free to ask again

PS Try to use java standards so I can tell UserInfo from userInfo quicker.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.