| | |
GTK Hangs & An Index Error
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2009
Posts: 41
Reputation:
Solved Threads: 0
This program hangs when trying to generate fixtures when the table is empty:
& when you try to generate fixtures when the table is full it gives a Index Error at 51:
why?
C# Syntax (Toggle Plain Text)
using System; using Gtk; using Mono.Data.Sqlite; using System.IO; public partial class MainWindow: Gtk.Window { //SQLite variables static SqliteConnection DataConn; static SqliteCommand DataComm = new SqliteCommand(); static SqliteDataReader DataReader; string dsn; //tree_1 variables Gtk.TreeViewColumn name_1 = new Gtk.TreeViewColumn (); Gtk.ListStore List_1 = new Gtk.ListStore (typeof (string)); Gtk.CellRendererText NameCell_1 = new Gtk.CellRendererText (); //tree_2 variables Gtk.TreeViewColumn home_team_2 = new Gtk.TreeViewColumn (); Gtk.TreeViewColumn away_team_2 = new Gtk.TreeViewColumn (); Gtk.TreeStore List_2 = new Gtk.TreeStore (typeof (string), typeof (string)); Gtk.CellRendererText homeCell_2 = new Gtk.CellRendererText (); Gtk.CellRendererText awayCell_2 = new Gtk.CellRendererText (); //Any Gtk.TreeIter iter; int numofteams; string[] teamsa; string[] homea; string[] awaya; int[,] fixturea; public void generate_fixtures() { Random rand = new Random(); int home; int away; int numoffix = numofteams/2; int j = 0; homea = new string[numoffix]; awaya = new string[numoffix]; int[] teamsused = new int[numofteams]; for (int i = 0; i < numoffix; i++){ do{ home = rand.Next(0, numofteams); away = rand.Next(0, numofteams); } while (home == away || fixturea[home,away] != 0 || teamsused[home] != 0 || teamsused[away] != 0); fixturea[home,away] = 1; homea[j] = teamsa[home]; awaya[j] = teamsa[away]; teamsused[home] = 1; teamsused[away] = 1; j++; } } public void generate_all_fixtures() { fixturea = new int[numofteams,numofteams]; DataComm.CommandText = "DELETE FROM fixture;"; DataComm.ExecuteNonQuery(); int blah = (numofteams-1) * 2; for (int i = 0; i <= blah; i++){ generate_fixtures(); for (int j = 0; j < numofteams/2; j++){ DataComm.CommandText = string.Format("INSERT INTO fixture VALUES (null, \"{0}\", \"{1}\", {2});", homea[j], awaya[j], i+1); DataComm.ExecuteNonQuery(); } } tree_2_add_data(); } public void generate_team_array() { DataComm.CommandText = "SELECT * FROM teams;"; DataReader = DataComm.ExecuteReader(); teamsa = new string[numofteams]; int i = 0; string returned; while (DataReader.Read()){ returned = DataReader["Name"].ToString(); teamsa[i] = returned; i++; } DataReader.Close(); } public void tree_1_add_data() { numofteams = 0; DataComm.CommandText = "SELECT * FROM teams;"; DataReader = DataComm.ExecuteReader(); string returned; while (DataReader.Read()){ returned = DataReader["Name"].ToString(); List_1.AppendValues(returned); numofteams += 1; } DataReader.Close(); generate_team_array(); } public void tree_2_add_data() { string day; List_2.Clear(); for (int i = 0; i < numofteams/2; i++){ DataComm.CommandText = string.Format("SELECT * FROM fixture where Day = {0};", i+1); DataReader = DataComm.ExecuteReader(); if (DataReader.HasRows){ day = string.Format("Day {0}", i+1); iter = List_2.AppendValues(day); } while (DataReader.Read()){ List_2.AppendValues(iter, DataReader["Home"].ToString(), DataReader["Away"].ToString()); numofteams += 1; } DataReader.Close(); } } public void tree_conf() { //tree_1 name_1.Title = "Name"; tree_1.AppendColumn(name_1); tree_1.Model = List_1; name_1.PackStart (NameCell_1, true); name_1.AddAttribute (NameCell_1, "text", 0); tree_1_add_data(); //tree_2 home_team_2.Title = "Home Team"; away_team_2.Title = "Away Team"; tree_2.AppendColumn(home_team_2); tree_2.AppendColumn(away_team_2); tree_2.Model = List_2; home_team_2.PackStart(homeCell_2, true); home_team_2.AddAttribute(homeCell_2, "text", 0); away_team_2.PackStart(awayCell_2, true); away_team_2.AddAttribute(awayCell_2, "text", 1); tree_2_add_data(); } public MainWindow (): base (Gtk.WindowType.Toplevel) { Build (); bool first = false; if (!File.Exists("league.db")){ SqliteConnection.CreateFile("league.db"); first = true; } string dsn = "Data Source=league.db;"; DataConn = new SqliteConnection(dsn); DataConn.Open(); DataComm.Connection = DataConn; if (first){ DataComm.CommandText = "CREATE TABLE teams (ID INTEGER PRIMARY KEY, Name TEXT);"; DataComm.ExecuteNonQuery(); DataComm.CommandText = "CREATE TABLE fixture (ID INTEGER PRIMARY KEY, Home TEXT, Away TEXT, Day INTEGER);"; DataComm.ExecuteNonQuery(); } tree_conf(); } protected void OnDeleteEvent (object sender, DeleteEventArgs a) { Application.Quit (); a.RetVal = true; } protected virtual void on_submit_1 (object sender, System.EventArgs e) { //if it's empty don't do anything string team = team_1.Text; if (team == ""){ return; } //Insert data into the table DataComm.CommandText = string.Format("INSERT INTO teams VALUES (null, \"{0}\");", team); DataComm.ExecuteNonQuery(); //Clear tree_1 List_1.Clear(); //Query database for teams tree_1_add_data(); } protected virtual void on_generate_2 (object sender, System.EventArgs e) { generate_all_fixtures(); } }
C# Syntax (Toggle Plain Text)
homea[j] = teamsa[home];
•
•
Join Date: Jul 2009
Posts: 908
Reputation:
Solved Threads: 145
0
#2 Oct 10th, 2009
This is the second time I've seen this project, which I cannot do anything with because I don't have your 3rd party libraries or data. I've noticed you made a few modifications since the previous thread.
Anyway, these lines look a little suspicious, and "blah" is probably not the best name you could have come up with...
I'm wondering whether you meant for "blah" to be
Is this an application that is available for free that you are modifying that we can download the original somewhere and get the 3rd party libraries installed?
Anyway, these lines look a little suspicious, and "blah" is probably not the best name you could have come up with...
C# Syntax (Toggle Plain Text)
int blah = (numofteams-1) * 2; for (int i = 0; i <= blah; i++)
I'm wondering whether you meant for "blah" to be
= numofteams * 2 - 1 and for condition to be i < blah ?Is this an application that is available for free that you are modifying that we can download the original somewhere and get the 3rd party libraries installed?
•
•
Join Date: Jun 2009
Posts: 41
Reputation:
Solved Threads: 0
0
#3 Oct 10th, 2009
I've stopped the freezing, but not the index error
C# Syntax (Toggle Plain Text)
using System; using Gtk; using Mono.Data.Sqlite; using System.IO; public partial class MainWindow: Gtk.Window { //SQLite variables static SqliteConnection DataConn; static SqliteCommand DataComm = new SqliteCommand(); static SqliteDataReader DataReader; string dsn; //tree_1 variables Gtk.TreeViewColumn name_1 = new Gtk.TreeViewColumn (); Gtk.ListStore List_1 = new Gtk.ListStore (typeof (string)); Gtk.CellRendererText NameCell_1 = new Gtk.CellRendererText (); //tree_2 variables Gtk.TreeViewColumn home_team_2 = new Gtk.TreeViewColumn (); Gtk.TreeViewColumn away_team_2 = new Gtk.TreeViewColumn (); Gtk.TreeStore List_2 = new Gtk.TreeStore (typeof (string), typeof (string)); Gtk.CellRendererText homeCell_2 = new Gtk.CellRendererText (); Gtk.CellRendererText awayCell_2 = new Gtk.CellRendererText (); //Any Gtk.TreeIter iter; int numofteams; int numofteamsOLD; string[] teamsa; string[] homea; string[] awaya; int[,] fixturea; public void generate_fixtures() { Random rand = new Random(); int home; int away; int numoffix = numofteams/2; Console.WriteLine("numofteams: {0}", numofteams); Console.WriteLine("numoffix : {0}", numoffix); int j = 0; homea = new string[numoffix]; awaya = new string[numoffix]; int[] teamsused = new int[numofteams]; int k = 0; for (int i = 0; i < numoffix; i++){ do{ home = rand.Next(0, numofteams); away = rand.Next(0, numofteams); k++; } while (home == away || fixturea[home,away] != 0 || teamsused[home] != 0 || teamsused[away] != 0); fixturea[home,away] = 1; Console.WriteLine(j); homea[j] = teamsa[home]; awaya[j] = teamsa[away]; teamsused[home] = 1; teamsused[away] = 1; j++; } } public void generate_all_fixtures() { fixturea = new int[numofteams,numofteams]; DataComm.CommandText = "DELETE FROM fixture;"; DataComm.ExecuteNonQuery(); int blah = (numofteams-1) * 2; for (int i = 0; i < blah; i++){ generate_fixtures(); for (int j = 0; j < numofteams/2; j++){ DataComm.CommandText = string.Format("INSERT INTO fixture VALUES (null, \"{0}\", \"{1}\", {2});", homea[j], awaya[j], i+1); DataComm.ExecuteNonQuery(); } } tree_2_add_data(); } public void generate_team_array() { DataComm.CommandText = "SELECT * FROM teams;"; DataReader = DataComm.ExecuteReader(); teamsa = new string[numofteams]; int i = 0; string returned; while (DataReader.Read()){ returned = DataReader["Name"].ToString(); teamsa[i] = returned; i++; } DataReader.Close(); } public void tree_1_add_data() { numofteams = 0; DataComm.CommandText = "SELECT * FROM teams;"; DataReader = DataComm.ExecuteReader(); string returned; while (DataReader.Read()){ returned = DataReader["Name"].ToString(); List_1.AppendValues(returned); numofteams += 1; } DataReader.Close(); generate_team_array(); } public void tree_2_add_data() { string day; List_2.Clear(); for (int i = 0; i < numofteams/2; i++){ DataComm.CommandText = string.Format("SELECT * FROM fixture where Day = {0};", i+1); DataReader = DataComm.ExecuteReader(); if (DataReader.HasRows){ day = string.Format("Day {0}", i+1); iter = List_2.AppendValues(day); } else { DataReader.Close(); return; } while (DataReader.Read()){ List_2.AppendValues(iter, DataReader["Home"].ToString(), DataReader["Away"].ToString()); numofteams += 1; } DataReader.Close(); } } public void tree_conf() { //tree_1 name_1.Title = "Name"; tree_1.AppendColumn(name_1); tree_1.Model = List_1; name_1.PackStart (NameCell_1, true); name_1.AddAttribute (NameCell_1, "text", 0); tree_1_add_data(); //tree_2 home_team_2.Title = "Home Team"; away_team_2.Title = "Away Team"; tree_2.AppendColumn(home_team_2); tree_2.AppendColumn(away_team_2); tree_2.Model = List_2; home_team_2.PackStart(homeCell_2, true); home_team_2.AddAttribute(homeCell_2, "text", 0); away_team_2.PackStart(awayCell_2, true); away_team_2.AddAttribute(awayCell_2, "text", 1); tree_2_add_data(); } public MainWindow (): base (Gtk.WindowType.Toplevel) { Build (); bool first = false; if (!File.Exists("league.db")){ SqliteConnection.CreateFile("league.db"); first = true; } string dsn = "Data Source=league.db;"; DataConn = new SqliteConnection(dsn); DataConn.Open(); DataComm.Connection = DataConn; if (first){ DataComm.CommandText = "CREATE TABLE teams (ID INTEGER PRIMARY KEY, Name TEXT);"; DataComm.ExecuteNonQuery(); DataComm.CommandText = "CREATE TABLE fixture (ID INTEGER PRIMARY KEY, Home TEXT, Away TEXT, Day INTEGER);"; DataComm.ExecuteNonQuery(); } tree_conf(); } protected void OnDeleteEvent (object sender, DeleteEventArgs a) { Application.Quit (); a.RetVal = true; } protected virtual void on_submit_1 (object sender, System.EventArgs e) { //if it's empty don't do anything string team = team_1.Text; if (team == ""){ return; } //Insert data into the table DataComm.CommandText = string.Format("INSERT INTO teams VALUES (null, \"{0}\");", team); DataComm.ExecuteNonQuery(); //Clear tree_1 List_1.Clear(); //Query database for teams tree_1_add_data(); } protected virtual void on_generate_2 (object sender, System.EventArgs e) { generate_all_fixtures(); } }
•
•
Join Date: Jul 2009
Posts: 908
Reputation:
Solved Threads: 145
0
#7 Oct 10th, 2009
•
•
•
•
"Is this an application that is available for free that you are modifying that we can download the original somewhere and get the 3rd party libraries installed? "
No it's my own app, it is made with Mono & GTK# on Linux instead of .Net
I tried downloading the command-line program Sqlite-3 6 18.zip thinking I could reference the assembly and resolve the above, but no luck. Any suggestions?
•
•
Join Date: Jul 2009
Posts: 908
Reputation:
Solved Threads: 145
0
#8 Oct 10th, 2009
I don't see how "j" can be the culprit since j is always equal to "i" and "i" is always < numofix and homea is sized at numoffix.
Try adding adding this debug statement and assignment before the homea[j] assignment:
The assert should happen if the empty string assignment (test) is going to fail...
Try adding adding this debug statement and assignment before the homea[j] assignment:
C# Syntax (Toggle Plain Text)
System.Diagnostics.Debug.Assert(i == j && j < numoffix && numoffix == homea.Length); homea[j] = ""; homea[j] = teamsa[home];
The assert should happen if the empty string assignment (test) is going to fail...
•
•
Join Date: Jun 2009
Posts: 41
Reputation:
Solved Threads: 0
0
#9 Oct 10th, 2009
•
•
•
•
I don't see how "j" can be the culprit since j is always equal to "i" and "i" is always < numofix and homea is sized at numoffix.
Try adding adding this debug statement and assignment before the homea[j] assignment:
C# Syntax (Toggle Plain Text)
System.Diagnostics.Debug.Assert(i == j && j < numoffix && numoffix == homea.Length); homea[j] = ""; homea[j] = teamsa[home];
The assert should happen if the empty string assignment (test) is going to fail...
C# Syntax (Toggle Plain Text)
Marshaling clicked signal Exception in Gtk# callback delegate Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: Array index is out of range. at MainWindow.generate_fixtures () [0x000cf] in /home/matio/Projects/leaguemanager/leaguemanager/MainWindow.cs:68 at MainWindow.generate_all_fixtures () [0x00043] in /home/matio/Projects/leaguemanager/leaguemanager/MainWindow.cs:84 at MainWindow.on_generate_2 (System.Object sender, System.EventArgs e) [0x00000] in /home/matio/Projects/leaguemanager/leaguemanager/MainWindow.cs:258 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] --- End of inner exception stack trace --- at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal) at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) at Gtk.Application.gtk_main() at Gtk.Application.Run() at leaguemanager.MainClass.Main(System.String[] args) in /home/matio/Projects/leaguemanager/leaguemanager/Main.cs:line 13
•
•
Join Date: Jul 2009
Posts: 908
Reputation:
Solved Threads: 145
0
#10 Oct 10th, 2009
Well, you didn't report whether it was actually "j", and I am still not convinced it is.
In this method,
why are you setting
It's too difficult to figure this out this way... If you tell me how to get the reference to the Mono.Data.Sqlite namespace, I'll help you figure this out.
The error text you posted is only partially useful and the line numbers it shows have probably moved since the code you posted prior.
In this method,
C# Syntax (Toggle Plain Text)
public void generate_team_array() { DataComm.CommandText = "SELECT * FROM teams;"; DataReader = DataComm.ExecuteReader(); teamsa = new string[numofteams]; int i = 0; string returned; while (DataReader.Read()){ returned = DataReader["Name"].ToString(); teamsa[i] = returned; i++; } DataReader.Close(); numofteamsREAL = i - 1; }
why are you setting
numofteamsREAL = i - 1 ? Shouldn't it be numofteamsREAL = i ?It's too difficult to figure this out this way... If you tell me how to get the reference to the Mono.Data.Sqlite namespace, I'll help you figure this out.
The error text you posted is only partially useful and the line numbers it shows have probably moved since the code you posted prior.
Last edited by DdoubleD; Oct 10th, 2009 at 1:58 pm.
![]() |
Similar Threads
- Undefined Index Error (PHP)
- undefined index error (PHP)
- Index error in PHP code (PHP)
- Undefined index error (PHP)
- Help ! Browswer hijacked, Zlod tojan & Symantec Error (Viruses, Spyware and other Nasties)
- Datagrid - no value at index ### error when scroll and sort (VB.NET)
- Error trapping while reading windows XP registry entries (Python)
- gtk.ComboBox (Python)
- Parse Error in PHP (PHP)
Other Threads in the C# Forum
- Previous Thread: Global property
- Next Thread: Dictionary Program. help!!
| Thread Tools | Search this Thread |






