Why do I get an error?

Hello,
What I want is for a new row to be inserted each time the last column has finished being edited. I add the data in each row to a Vector() after every row. I get an ArrayIndexOutOfBoundsException when I want to insert a new row. Do you know why this happens?
Thanks
Hannah
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.util.*;
public class TestGUI extends JFrame {
JTable table;
ListSelectionModel lsm;
Vector goals;
Object player = new String("");
Object minute = new String("");
boolean hasrecords;
public TestGUI() {
super("TestGUI");
goals = new Vector();
goals.addElement(new Goal("", ""));
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new FlowLayout());
JPanel pan = new JPanel(new BorderLayout());
table = new JTable(new GoalsTableModel());
table.setCellSelectionEnabled(true);
TableColumn column;
column = table.getColumnModel().getColumn(1);
DefaultCellEditor celleditor = new DefaultCellEditor(new JTextField());
celleditor.addCellEditorListener(new TableCellEditorListener());
column.setCellEditor(celleditor);
pan.add(table.getTableHeader(), BorderLayout.NORTH);
pan.add(table, BorderLayout.CENTER);
getContentPane().add(pan);
setSize(500,500);
show();
class GoalsTableModel extends DefaultTableModel {
int numrows = 1;
public int getColumnCount() {
return 2;
public int getRowCount() {
return numrows;
public String getColumnName(int col) {
if(col==0) {
return "Player";
else {
return "Minute";
public Object getValueAt(int row, int col) {
if(!hasrecords) {
     if(col==0) {
     return player;
     else {
     return minute;
else {
Goal goalrecord = (Goal)goals.elementAt(row);
if(col==0) {
return goalrecord.player;
if(col==1) {
return goalrecord.minute;
else {
return null;
public void setValueAt(Object value, int row, int col) {
if(col==0) {
player = value;
if(col==1) {
minute = value;
public boolean isCellEditable(int row, int col) {
return true;
class Goal {
String player;
String minute;
public Goal(String player, String minute) {
this.player = player;
this.minute = minute;
class TableCellEditorListener implements CellEditorListener {
public void editingStopped(ChangeEvent e) {
goals.setElementAt(new Goal(player.toString(), minute.toString()), table.getSelectedRow());
DefaultTableModel tableModel = (DefaultTableModel)table.getModel();
     if(table.getSelectedRow() == tableModel.getRowCount() - 1) {
     String[] data = new String[] {"", ""};
     System.out.println(((Goal) goals.lastElement()).player);
     System.out.println(((Goal) goals.lastElement()).minute);
     goals.addElement(new Goal("", ""));
     GoalsTableModel goalstablemodel = (GoalsTableModel) table.getModel();
     tableModel.setRowCount(tableModel.getRowCount() + 1);
     goalstablemodel.numrows = tableModel.getRowCount() + 1;
hasrecords=true;
public void editingCanceled(ChangeEvent e) {
public static void main(String[] args) {
new TestGUI();

You should always indicate the line of code where the error occurs.   Also, the value of the variables in that line, as that tells you what the problem is.
There are several places where you use '+' instead of '&' with mixed types which can cause this error.
However this line:
  Dim orderid As Integer = (ds.Tables(0).Rows(0).Item(0)) + 1
is most likely the problem if you haven't checked first that there is a valid order ID returned from the query.  If the table is empty then you should initialise the ID to an arbitrary value instead of trying to calculate it.

Similar Messages

  • Why do I get an error message in safari 5.1 telling me to restart in 32 bit mode in order to "view the movie" when I first start safari on opening page?

    why do I get an error message when I start safari 5.1 telling me I need to open browser in 32 bit mode in order to "view movie" ? This occurs when I start safari on the opening page (the page with all the boxes for most viewed web sites). This had never occurred with safari up until the latest updates to safari & OSX [Version 5.1 (6534.50)] and OSX 10.6.8.
    also, I'm not trying to view a movie - this occurs for the page previews that load when safari opens.
    thanks.

    go here:
    http://get.adobe.com/shockwave/otherversions/
    choose "different version">full 64 bit and download - seems to have solved probem...let you know if it happens again

  • Why am I getting an error message when trying to use a template?

    Why am I getting an error message when trying to use a Pages template?

    You are getting an error message because there is an error.
    Knowing wht version of Pages you are using, what template you are attempting to open, and what error message Pages is sending you might help determine why you are getting that specific rror message. Without those, the first sentence above i pretty much all that can be said with any assurance.
    Regards,
    Barry

  • Why do I get "generic error" message when trying to upload a self-created, 1hr .wmv file?

    I went through the forums and made sure that any blocks or copywrites weren't triggered by the file, it's clean and can be opened using a media player and other video editing software like windows MovieMaker. I keep getting "The importer reported a generic error" message and have no idea how to proceed. Can someone please help?

    Re: Why do I get "generic error" message when trying to upload a self-created, 1hr .wmv  file?
    This ARTICLE starts with a checklist on setting up a computer to run PrE best, then goes into a series of links for tuning up one's computer and OS, and then links on troubleshooting.
    There is also a link on posting all necessary info, to help others help you.
    Without knowing much more about your system, it is impossible to say much beyond that WMV's are tough assests to work with, requiring a lot of CPU horsepower.
    Good luck,
    Hunt

  • Why am i getting an error message that says "an unknown error has occured" when i try to update my apps in the app store

    Can someone please offer some suggestions why I am getting an error message that says "an unknown error has occured" when I try to download or update my apps in the app store?
    Thanks!
    disregard! i noticed someone else's post about signing out of the app store and signing in again and it worked.....

    Hi ...
    Try here > Mac App Store: "An unknown error occurred (100)" when purchasing
    If that doesn't help, drag the App Store icon straight up off your Dock so it goes, "poof".
    Now drag the App Store icon from your Applications folder to the Dock. Try updating your apps.

  • Why do I get an error message when I try to sync my IPAD with ITunes? Message reads Cannot be used because Apple Mobile Device Service has not been started.

    Why do I get an error message when I try to sync my IPAD with ITunes? Message reads Cannot be used because Apple Mobile Device Service has not been started.

    AMDS for Windows
    http://support.apple.com/kb/TS1567

  • I get missing plug-in error when opening my online bill which is in PDF format. I am using a 2010 Macbook with the latest version of Safari and Adobe suite installed in my computer. Why do I get this error? What should I do?

    I get missing plug-in error when opening my online bill which is in PDF format. I am using a 2010 Macbook with the latest version of Safari and Adobe suite installed in my computer. Why do I get this error? What should I do?

    In relation to my previous inquiry regarding inability to view a pdf file using Safari...
    Is it possible that I can view other online bills from other website but not this particular bill from one specific website?
    Sorry if I missed any important point in this article -->Apple Safari 5.1 and Adobe Reader/Acrobat Advisory
    Thanks again!

  • Why do I get this error message when I open Organizer in Photoshop Elements 11 "Elements Organizer has stopped working"? My only option is to Close Program so I am effectively locked out of my photo catalogue.  I have reinstalled the program to no avail.

    Why do I get this error message when I open Organizer in Photoshop Elements 11 "Elements Organizer has stopped working"? My only option is to Close Program so I am effectively locked out of my photo catalogue. I have tried reinstalling the program but it made no difference to the error message.
    Could someone help please?  Steph

    Hi,
    Please give a try to Photoshop Elements (PSE) knowledge base. steps mentioned on this and see if it works.
    Regards
    Kishan

  • Why do I get this error when trying to use my bluetooth headset as a listening device? There was an error connecting to your audio device. Make sure it is turned on and in range. The audio portion of the program you were using may have to be restarted.

    Why do I get this error when trying to use my bluetooth headset as a listening device? There was an error connecting to your audio device. Make sure it is turned on and in range. The audio portion of the program you were using may have to be restarted.

    I may have already resolved this issue buy removing the device from my computer and re-pairing it. It is currently working just fine.

  • More than maximum 5 filtered album lists trying to register. This will fail,Why i am getting this error when i pick video from Photo library.

    I am able to pick 4 videos from the Photo library in my iPhoneAPP but when i try to pick 5th one it throws an error:
    "More than maximum 5 filtered album lists trying to register. This will fail,Why i am getting this error when i pick video from Photo library."

    Hello Tate r Bulic
    I don't have any idea how to remove this error,can i pick more than 5 videos from the photo library...
    If it's then please help me and gimme idea..Thanks

  • According to my network provider (Amaysim/Optus) Tethering is enabled, so why do I get this error message "to enable personal hotspot on this account, contact OPTUS"

    According to my network provider (Amaysim/Optus) Tethering is enabled, so why do I get this error message "to enable personal hotspot on this account, contact OPTUS"
    Amysim/Optus support can not help.
    I can not check or change any network settings (no APN settings)
    I have synced phone using latest itunes (10.5.3).
    Phone software is up to date (5.0.1).
    Network settings have been reset.
    SIM card has been taken out and put back in.
    Phone has been switched off/on again.
    Another sim card from virgin works ok (hotspot option is visible and can be turned on/off as required)
    The Amaysim/Optus SIM card can be put into another phone (android) and tethering/hotspot works fine.
    Can anyone provide solution to this nightmare?

    I am having the same issue although i have an iphone 5. I have contacted Live connected numerous times an tried everything imaginable to solve the issue. Is it possibly a handset issue? I cant recieve any help from optus as im with live connected, they cant help me and apple keep telling me to contact your carrier ( live connected). Seems to make me want to switch providers pretty shortly..
    please let me know if you can solve your issue and maybe it can help me too..

  • Why do I get the error message: "The file "iTunes Library" cannot be read because it was created by a newer version of iTune." I am using iTunes9.1.1 which, I believe, is the highest for OS 10.4.11 ?

    Why do I get the error message: "The file "iTunes Library" cannot be read because it was created by a newer version of iTune." I am using iTunes9.1.1 which, I believe, is the highest for OS 10.4.11 ?

    Hello,
    Did you reinstall lately?
    My 10.4.11 Drive seemes to have iTunes 7.6.2 on it, have you tried Software update to see if iTunes is listed?
    Another 10.4.11 drive has iTunes 6.05 on it... I hate upgrading iTunes, seems worse at every upgrade.
    The 10.5.8 drive I'm booted from now has iTunes 8.02 on it.

  • Why do I get certificate errors?

    Why am I getting certificate errors for Facebook and other sites?  Why am I getting Invalid URLs as well?

    It started about 1.5 - 2 months ago.  I can go to CNN, yahoo news etc and I get certificate errors for Facebook.  It always say something about that Safari can validate certificate for s-static facebook or something like that.

  • InDesign CS 5.5 - Why am I getting an error message saying my files ( that I created in 5.5 ) can not be opened because they are created in CS6? Says I have to open in 6 and back save to 4.

    Why am I getting an error message saying my files ( that I created in 5.5 ) can not be opened because they are created in CS6? Says I have to open in 6 and back save to 4.

    Ask in the ID forum and provide at least some useful info like system specs, what's contained in the files, where they are stored...
    Mylenium

  • Why am I getting this error?

    Hello,
    I am trying to call my Java class from a JSP page. I am getting this error:
    Generated servlet error:
    C:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\em\jsp\Test_0005fSummarySBU_0005fscreen$jsp.java:82: Wrong number of arguments in constructor.
    strQuery=new ListReturn(strEssUser, strProcessingMonth, strProcessingYear);
    I don't understand why I am getting this error as I pass three paramters to the Java class, and I accept three parameters in the constructor.
    JSP:
    <!-- META TAG is necessary to ensure page recompiles--------------->
    <META Http-Equiv="Expires" Content="0">
    <META Http-Equiv="Pragma" Content="no-cache">
    <HTML>
    <!-- The two Java Classes used to build the AlphaBlox query -->
    <%@ page import="com.home.tool.reporting.*" %>
    <%@ page errorPage="run_error.jsp" %>
    <%@ page import="java.util.List,
                     java.util.Collection,
                java.net.URLDecoder" %>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <TITLE>Economic Model - Summary SBU Report</TITLE>
    <!--Run the onload here, re-retrieve params BM and Breport, pass to onload---------->
    <BODY bgcolor=#ffffff>
    <%
                    Collection strQuery = null;
                    String strEssUser = "test";
                    String strProcessingMonth = "JUL";
                    String strProcessingYear = "2002";
                    strQuery=new ListReturn(strEssUser, strProcessingMonth, strProcessingYear);
                    System.out.println(strQuery);
    %>
    </BODY>
    </HTML>Java class:
    package com.home.tool.reporting;
    import java.net.URL;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class ListReturn extends ReportQueryBuilder
            public void ListReturn()
            public Collection ListReturn(String userID, String pMonth, String pYear)
                throws ReportQueryBuilderException
                //declare Collection store Value-Object pairs
                Collection c = new ArrayList();
                //declare and initialize variables
                CallableStatement cs = null;
                ResultSet rs = null;
                // declare call for stored procedure to pass in three parameters
                String pass = "{Call dbo.p_rep_srSbuList(?, ?, ?)}";
                try
                    //open CallableStatement using JDBC connection to SQL database
                    cs = con.prepareCall(pass);
                    //set IN parameters
                    cs.setString(1, userID);
                    cs.setString(2, pMonth);
                    cs.setString(3, pYear);
                    //execute call and return result set
                    rs = cs.executeQuery();
                    //loop through result set storing each record as a Value-Object pair
                    while(rs.next())
                        c.add(new ListBoxValueObjects(rs.getString(1), rs.getString(2)));
                catch (SQLException sqle)
              throw new ReportQueryBuilderException(replaceToken("Problems executing query: "+sqle.getMessage(), "'", "\\'"));
                finally
                    try
                        //close the Result Set and CallableStatement
                        rs.close();
                        cs.close();
                    catch(Exception e)
                        System.out.print("\nFATAL   : " + e);
                        System.out.print("\nFATAL   : " + e);
                return c;
    }Does anyone see whay I am getting this error??
    I can't figure out the problem!

    change this:
    <%
         Collection strQuery = null;
         String strEssUser = "test";
         String strProcessingMonth = "JUL";
         String strProcessingYear = "2002";
         strQuery=new ListReturn(strEssUser, strProcessingMonth, strProcessingYear);
         System.out.println(strQuery);
    %>To this:
    <%
         Collection strQuery=null;
         String strEssUser="test";
         String strProcessingMonth="JUL";
         String strProcessingYear="2002";
         lr=new ListReturn(strEssUser, strProcessingMonth, strProcessingYear);
         System.out.println(lr.getQuery())
    %>Then make a new public method in your Java called getQuery()
    public Collection getQuery();Do what you need to do to process it and return the value in getQuery. You will also probably need to make private variables in you declaration to do the processing on.

  • Why am I getting an error when I place two OAM files one after the other in different pages?

    Why am I getting an error when I place two OAM files one after the other in different pages? They do not load or play correctly.  They are both configured to play automatically with a .125 second delay and both have a white rectangle "poster" over for a hidden effect.

    Thanks for the idea, Scott! I initially tried your idea, but my OAM files were still not loading correctly.  I tried other combinations of OAM files, and it seems to work fine.
    Back to my original OAM files: I made sure that my elements in my Edge Animate project had different names. I originally copied parts of some elements from one to another, and I think it was confusing to DPS to read it. 

Maybe you are looking for

  • Battery heating up iOS 7.1.2

    Since updating from iOS 7.1 to iOS 7.1.2 I'm experiencing a hotter than normal battery when levels drop down to about 20% and the phone is in use. just wondering if anyone else also has same problem

  • In Purchasing A/P - A/P Credit Memo -- how to correct entry??

    Hi guys! Please advise me how to delete a double entry: by error an A/P Credit memo was entered twice, the same amount, the same date.. How can I correct it and what type of reconciliation I would need afterwards? Thank you! Message was edited by: An

  • Question on import java.util.ArrayList, etc.

    Hi, I was wondering what the following meant and what the differences were. When would I have to use these: import java.util.ArrayList; import java.util.Collections; <--I especially don't understand what this means import java.util.Comparator; <---sa

  • Duplicate Candidate Check in iRecruitment

    Hi, Does irecruitment hold a functionality of duplicate candidate check? for e.g. One of my vendors have already supplied me with a profile "A", another vendor suppiles me with the same profile "A". But I want a check happening at the agency front it

  • Windows 7 shutting down

    Downloaded windows 7 running it through bootcamp but when it gets past the part where it shows the shiny windows logo it shuts down? Help please