Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
Common Null Execption unhandled
Results 1 to 2 of 2

Thread: Common Null Execption unhandled

  1. #1

    Common Null Execption unhandled

    From what I read this is a common problem for new programmers, Witch I am. So if any one can help me track down my problem I'll REP ++ you.

    But I keep getting a Null Exception Unhanded.
    I understand Null is when a variable has no value. But I'll post my code and see if anyone can help me shed some light on this.

    clientSettingsWindow.cs
    [code=c#]
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Dbot.Loader;
    namespace Dbot
    {
    public partial class clientSettingsWindow : Form
    {
    public List<ClientSetting> clientSettings = new List<ClientSetting>();
    public clientSettingsWindow()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    this.DialogResult = DialogResult.OK;
    this.Close();
    }

    private void newButton_Click(object sender, EventArgs e)
    {
    addClientSettingWindow add = new addClientSettingWindow();
    if (add.ShowDialog() == DialogResult.OK)
    {
    ClientSetting temp = new ClientSetting();
    temp = add.CS;
    temp.version = add.CS.version;
    temp.location = add.CS.location;
    if (temp != null)
    {
    clientSettings.Add(temp);
    }
    foreach (ClientSetting C in clientSettings)
    {
    ClientSettingListBox.Items.Clear();
    ClientSettingListBox.Items.Add(C.version);
    }
    }
    }
    }
    }
    [/code]
    addClientSettingsWindow.cs
    [code=c#]
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Dbot.Loader;

    namespace Dbot
    {
    public partial class addClientSettingWindow : Form
    {
    public ClientSetting CS = new ClientSetting();
    public addClientSettingWindow()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    if (CS.version <= 7.9)
    {
    MessageBox.Show("You Need to Select a version");
    return;
    }
    if (CS.location == null)
    {
    MessageBox.Show("You need to Select a Client");
    return;
    }

    this.DialogResult = DialogResult.OK;
    this.Close();
    }

    private void versionComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
    CS.version = Convert.ToDouble(versionComboBox.SelectedItem);
    }

    private void button3_Click(object sender, EventArgs e)
    {
    OpenFileDialog file = new OpenFileDialog();
    file.InitialDirectory = "C:\\Program Files (x86)\\Tibia";
    file.Filter = "Tibia (*.exe)|tibia.exe";
    file.RestoreDirectory = true;
    if (file.ShowDialog() == DialogResult.OK)
    {
    locationLabel.Text = file.FileName;
    CS.location = file.FileName;
    }
    }

    private void button2_Click(object sender, EventArgs e)
    {
    this.DialogResult = DialogResult.Cancel;
    this.Close();
    }
    }
    }
    [/code]

    Here is my class file that I am using, So all code that is used is available to help me track this problem down.

    TibiaLoader.cs
    [code=c#]
    using Tibia.Util;

    namespace Dbot.Loader
    {
    public class Clients
    {
    public Client client;
    public Player player;
    }
    public class ClientSetting
    {
    public String location;
    public Double version;
    }
    public class Favorates
    {
    public int index;
    public String name;
    public String ip;
    public int port;
    public Favorates()
    {
    name = "N/A";
    port = 7171;
    ip = "127.0.0.1";
    }
    public void Load()
    {

    }
    public void New(int Index, String Name, String IP, int Port)
    {
    index = Index;
    name = Name;
    ip = IP;
    port = Port;
    }
    }
    }
    [/code]

    So i keep haveing the probelm in the clientSettingsWindow.cs at this line
    [code=c#]
    if (temp != null)
    {
    clientSettings.Add(temp);
    }
    [/code]
    when it trys to add the temp to the list is where I keep getting the null execption unhandled. I do understand that the clientSettings is Null but in my debugger temp is not null when i'm adding the values to the list. I don't understand why it's not adding it to the list and makeing the clientSettings Not null.

  2. #2

    RE: Common Null Execption unhandled

    Well... I figured it out.. I think... LOL well it works.

    But this concludes at least making new Client Settings for the Client Launcher in my bot. Now to Edit and Delete them. Whoo... Should be pretty easy though. The part i dread is saving the settings to a file and loading them from a file. But since i used a class to hold the objects i'm hopeing that part isn't to hard using XML. This is about the only data I'm saving client side.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •