I am unsure what the problem is, I get this error after checking an item in the checkedlistbox:
The full output:
I don't really understand what the problem is, the code is supposed to get data from a website which is working, partly. I am reading the information fine as you can tell in the MessageBox popups. Perhaps someone could show me what I'm doing wrong?
The code:
main.cs
main.Designer.cs
And the link to the XML for the CharacterSheet: https://api.eveonline.com/char/CharacterSheet.xml.aspx?keyID=1688140&vCode=O9f9WAG5B20BlbTg8t2GiyEpdQS3ZYA5n6uq7woyYuWcvS6XfwAGR6CLUVnLT3Wq&characterID=282200859
I would appreciate any help, thanks
/>
A first chance exception of type 'System.NullReferenceException' occurred in SpaceshipList.exe An unhandled exception of type 'System.NullReferenceException' occurred in SpaceshipList.exe Additional information: Object reference not set to an instance of an object. The program '[1044] SpaceshipList.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
The full output:
'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\Bonnie\documents\visual studio 2012\Projects\SpaceshipList\SpaceshipList\bin\Debug\SpaceshipList.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Serialization.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\XamlBuildTask\v4.0_4.0.0.0__31bf3856ad364e35\XamlBuildTask.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. The thread 'vshost.NotifyLoad' (0x1a80) has exited with code 0 (0x0). The thread '<No Name>' (0xc64) has exited with code 0 (0x0). The thread 'vshost.LoadReference' (0x14b0) has exited with code 0 (0x0). 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'c:\users\bonnie\documents\visual studio 2012\Projects\SpaceshipList\SpaceshipList\bin\Debug\SpaceshipList.exe', Symbols loaded. 'SpaceshipList.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. A first chance exception of type 'System.NullReferenceException' occurred in SpaceshipList.exe An unhandled exception of type 'System.NullReferenceException' occurred in SpaceshipList.exe Additional information: Object reference not set to an instance of an object. The program '[1044] SpaceshipList.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
I don't really understand what the problem is, the code is supposed to get data from a website which is working, partly. I am reading the information fine as you can tell in the MessageBox popups. Perhaps someone could show me what I'm doing wrong?
The code:
main.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
namespace SpaceshipList
{
public partial class main : Form
{
string[] charNameLB = new string[3];
public main()
{
InitializeComponent();
}
private void CharIDTextBox_TextChanged(object sender, EventArgs e)
{
}
private void APIKeyTextBox_TextChanged(object sender, EventArgs e)
{
}
private void Submit_Click(object sender, EventArgs e)
{
CharacterNameList.Items.Clear();
string ID = CharIDTextBox.Text;
string API = APIKeyTextBox.Text;
string url = "https://api.eveonline.com/account/characters.xml.aspx?keyID=" + ID + "&vCode=" + API;
XDocument xmlDoc = Xdocument.Load(url);
var characters = from row in xmlDoc.Descendants("row")
select new
{
charName = row.Attribute("name").Value,
charID = row.Attribute("characterID").Value
};
int i = 0;
foreach(var row in characters)
{
CharacterNameList.Items.Add(row.charName, CheckState.Unchecked);
//characterID = row.charID;
charNameLB[i] = row.charName;
++i;
}
i = 0;
}
private void CharacterNameList_ItemCheck(object sender, ItemCheckEventArgs e)
{
string ID = CharIDTextBox.Text;
string API = APIKeyTextBox.Text;
string characterID = "";
string url = "https://api.eveonline.com/account/characters.xml.aspx?keyID=" + ID + "&vCode=" + API;
var checkedListBox = (CheckedListBox)sender;
string checkedItemText = checkedListBox.Items[e.Index].ToString();
if (e.NewValue == CheckState.Checked)
{
XDocument xmlDoc = Xdocument.Load(url);
var characters = from row in xmlDoc.Descendants("row")
select new
{
charID = row.Attribute("characterID").Value,
charName = row.Attribute("name").Value
};
foreach (var row in characters)
{
if (checkedItemText == row.charName)
{
characterID = row.charID;
MessageBox.Show(characterID);
}
}
url = "https://api.eveonline.com/char/CharacterSheet.xml.aspx?keyID=" + ID + "&vCode=" + API + "&characterID=" + characterID;
MessageBox.Show(url);
XDocument xmlDocProfile = Xdocument.Load(url);
var characterProfile = from result in xmlDocProfile.Descendants("result")
select new
{
charID = result.Element("characterID").Value,
charName = result.Element("name").Value,
DoB = result.Element("DoB").Value,
race = result.Element("race").Value,
bloodline = result.Element("bloodline").Value,
ancestry = result.Element("ancestry").Value,
gender = result.Element("gender").Value,
corporationName = result.Element("corporationName").Value,
allianceName = result.Element("allianceName").Value,
cloneName = result.Element("cloneName").Value,
cloneSkillPoints = result.Element("cloneSkillPoints").Value,
balance = result.Element("balance").Value
};
/*var characterAttributes = from attributes in xmlDoc.Descendants("attributes")
select new
{
intelligence = attributes.Element("intelligence").Value,
memory = attributes.Element("memory").Value,
charisma = attributes.Element("memory").Value,
perception = attributes.Element("perception").Value,
willpower = attributes.Element("willpower").Value
};
var characterSkills = from skills in xmlDoc.Descendants("rowset")
select new
{
skillID = skills.Attribute("typeID").Value,
skillLVL = skills.Attribute("level").Value
};*/
foreach (var profile in characterProfile)
{
DescriptionBox.Text += "Character ID: " + profile.charID;
DescriptionBox.Text += "\nCharacter Name: " + profile.charName;
}
/*foreach (var skill in characterSkills)
{
switch (skill.skillID)
{
case "3300":
{
DescriptionBox.Text = "Gunnery: " + skill.skillLVL;
SpaceShipList.Items.Add("Gunnery: " + skill.skillLVL.ToString());
break;
}
}
}*/
}
else
{
SpaceShipList.Items.Remove(CharacterNameList.SelectedItem.ToString());
}
}
private void DescriptionBox_TextChanged(object sender, EventArgs e)
{
}
}
}
main.Designer.cs
namespace SpaceshipList
{
partial class main
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.CharacterID = new System.Windows.Forms.Label();
this.CharIDTextBox = new System.Windows.Forms.TextBox();
this.APIKey = new System.Windows.Forms.Label();
this.APIKeyTextBox = new System.Windows.Forms.TextBox();
this.Submit = new System.Windows.Forms.Button();
this.CharacterNameList = new System.Windows.Forms.CheckedListBox();
this.SpaceShipList = new System.Windows.Forms.ListBox();
this.DescriptionBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// CharacterID
//
this.CharacterID.AutoSize = true;
this.CharacterID.Location = new System.Drawing.Point(12, 13);
this.CharacterID.Margin = new System.Windows.Forms.Padding(0);
this.CharacterID.Name = "CharacterID";
this.CharacterID.Size = new System.Drawing.Size(63, 13);
this.CharacterID.TabIndex = 0;
this.CharacterID.Text = "Character ID";
//
// CharIDTextBox
//
this.CharIDTextBox.BackColor = System.Drawing.SystemColors.ButtonFace;
this.CharIDTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.CharIDTextBox.ForeColor = System.Drawing.SystemColors.InactiveCaptionText;
this.CharIDTextBox.Location = new System.Drawing.Point(84, 13);
this.CharIDTextBox.Margin = new System.Windows.Forms.Padding(0, 4, 0, 4);
this.CharIDTextBox.Name = "CharIDTextBox";
this.CharIDTextBox.Size = new System.Drawing.Size(98, 21);
this.CharIDTextBox.TabIndex = 1;
this.CharIDTextBox.Text = "1688140";
this.CharIDTextBox.TextChanged += new System.EventHandler(this.CharIDTextBox_TextChanged);
//
// APIKey
//
this.APIKey.AutoSize = true;
this.APIKey.Location = new System.Drawing.Point(12, 43);
this.APIKey.Margin = new System.Windows.Forms.Padding(0);
this.APIKey.Name = "APIKey";
this.APIKey.Size = new System.Drawing.Size(42, 13);
this.APIKey.TabIndex = 2;
this.APIKey.Text = "API Key";
//
// APIKeyTextBox
//
this.APIKeyTextBox.BackColor = System.Drawing.SystemColors.ButtonFace;
this.APIKeyTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.APIKeyTextBox.ForeColor = System.Drawing.SystemColors.InactiveCaptionText;
this.APIKeyTextBox.Location = new System.Drawing.Point(84, 39);
this.APIKeyTextBox.Margin = new System.Windows.Forms.Padding(0, 4, 0, 4);
this.APIKeyTextBox.Name = "APIKeyTextBox";
this.APIKeyTextBox.Size = new System.Drawing.Size(98, 21);
this.APIKeyTextBox.TabIndex = 3;
this.APIKeyTextBox.Text = "O9f9WAG5B20BlbTg8t2GiyEpdQS3ZYA5n6uq7woyYuWcvS6XfwAGR6CLUVnLT3Wq";
this.APIKeyTextBox.TextChanged += new System.EventHandler(this.APIKeyTextBox_TextChanged);
//
// Submit
//
this.Submit.BackColor = System.Drawing.SystemColors.ScrollBar;
this.Submit.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.Submit.Cursor = System.Windows.Forms.Cursors.Default;
this.Submit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Submit.ForeColor = System.Drawing.SystemColors.InactiveCaptionText;
this.Submit.Location = new System.Drawing.Point(122, 75);
this.Submit.Margin = new System.Windows.Forms.Padding(0, 4, 0, 4);
this.Submit.Name = "Submit";
this.Submit.Size = new System.Drawing.Size(60, 22);
this.Submit.TabIndex = 5;
this.Submit.Text = "Submit";
this.Submit.UseVisualStyleBackColor = false;
this.Submit.Click += new System.EventHandler(this.Submit_Click);
//
// CharacterNameList
//
this.CharacterNameList.BackColor = System.Drawing.SystemColors.ButtonFace;
this.CharacterNameList.Checkonclick = true;
this.CharacterNameList.ForeColor = System.Drawing.SystemColors.InactiveCaptionText;
this.CharacterNameList.FormattingEnabled = true;
this.CharacterNameList.Location = new System.Drawing.Point(192, 13);
this.CharacterNameList.Margin = new System.Windows.Forms.Padding(0, 4, 0, 4);
this.CharacterNameList.Name = "CharacterNameList";
this.CharacterNameList.Size = new System.Drawing.Size(122, 84);
this.CharacterNameList.TabIndex = 7;
this.CharacterNameList.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.CharacterNameList_ItemCheck);
//
// SpaceShipList
//
this.SpaceShipList.BackColor = System.Drawing.SystemColors.ButtonFace;
this.SpaceShipList.ForeColor = System.Drawing.SystemColors.InactiveCaptionText;
this.SpaceShipList.FormattingEnabled = true;
this.SpaceShipList.Location = new System.Drawing.Point(318, 13);
this.SpaceShipList.Margin = new System.Windows.Forms.Padding(0, 4, 0, 4);
this.SpaceShipList.Name = "SpaceShipList";
this.SpaceShipList.Size = new System.Drawing.Size(236, 329);
this.SpaceShipList.TabIndex = 9;
//
// DescriptionBox
//
this.DescriptionBox.BackColor = System.Drawing.SystemColors.ButtonFace;
this.DescriptionBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.DescriptionBox.Location = new System.Drawing.Point(12, 102);
this.DescriptionBox.Multiline = true;
this.DescriptionBox.Name = "DescriptionBox";
this.DescriptionBox.ReadOnly = true;
this.DescriptionBox.Size = new System.Drawing.Size(302, 240);
this.DescriptionBox.TabIndex = 10;
this.DescriptionBox.TextChanged += new System.EventHandler(this.DescriptionBox_TextChanged);
//
// main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ButtonFace;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.ClientSize = new System.Drawing.Size(563, 351);
this.Controls.Add(this.DescriptionBox);
this.Controls.Add(this.SpaceShipList);
this.Controls.Add(this.CharacterNameList);
this.Controls.Add(this.Submit);
this.Controls.Add(this.APIKeyTextBox);
this.Controls.Add(this.APIKey);
this.Controls.Add(this.CharIDTextBox);
this.Controls.Add(this.CharacterID);
this.Cursor = System.Windows.Forms.Cursors.Default;
this.Font = new System.Drawing.Font("Corbel", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.ForeColor = System.Drawing.SystemColors.InactiveCaptionText;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Margin = new System.Windows.Forms.Padding(0, 4, 0, 4);
this.MaximizeBox = false;
this.Name = "main";
this.ShowIcon = false;
this.Text = "Spaceship List";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label CharacterID;
private System.Windows.Forms.TextBox CharIDTextBox;
private System.Windows.Forms.Label APIKey;
private System.Windows.Forms.TextBox APIKeyTextBox;
private System.Windows.Forms.Button Submit;
private System.Windows.Forms.CheckedListBox CharacterNameList;
private System.Windows.Forms.ListBox SpaceShipList;
private System.Windows.Forms.TextBox DescriptionBox;
}
}
And the link to the XML for the CharacterSheet: https://api.eveonline.com/char/CharacterSheet.xml.aspx?keyID=1688140&vCode=O9f9WAG5B20BlbTg8t2GiyEpdQS3ZYA5n6uq7woyYuWcvS6XfwAGR6CLUVnLT3Wq&characterID=282200859
I would appreciate any help, thanks