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!