NullReferenceException

03/15/2011 16:42 iStefan#1
Alright, This Damn Exception annoys me as fuck , and I've got No Idea why.
I Believe I'm missing something.. Can somebody remind me what is it?
I know It's un-pro question but ermm... here we go.
[Only registered and activated users can see links. Click Here To Register...]
03/15/2011 16:46 Ian*#2
Declare GUI.

GUI myGUI = new GUI();
03/15/2011 20:28 iStefan#3
Why "new GUI();" ?
In Program.cs I Have public static iManager GUI; // iManager is the class(form)
03/15/2011 20:40 .Kinshi#4
Classes need to be initialized.

Read some programming books to get a better grasp.
03/15/2011 21:59 iStefan#5
Quote:
Originally Posted by .Kinshi View Post
Classes need to be initialized.

Read some programming books to get a better grasp.
Yes but Then It Throws "No Source Available" ...
03/17/2011 09:55 Arco.#6
Quote:
Originally Posted by iStefan View Post
Yes but Then It Throws "No Source Available" ...
Read some programming books to get a better grasp.
03/17/2011 10:58 shitboi#7
Quote:
Originally Posted by iStefan View Post
Yes but Then It Throws "No Source Available" ...
Ian already made it so clear for you. Ask yourself, do you see the declaration or even the definition for GUI somewhere in your code?

I'll give you an example, tell me what is wrong.
Code:
int main(){
    printf("%d", [B]var[/B]);
    return 0;
}
03/17/2011 13:43 iStefan#8
Quote:
Originally Posted by shitboi View Post
Ian already made it so clear for you. Ask yourself, do you see the declaration or even the definition for GUI somewhere in your code?

I'll give you an example, tell me what is wrong.
Code:
int main(){
    printf("%d", [B]var[/B]);
    return 0;
}
Then, var isn't declared. It's the same if i do in C# . Console.WriteLine(string); lmao.
and no need to bold, I'm not so noobish, I just Dunno what am I forgettin'
03/17/2011 14:39 shitboi#9
in your first post, you have an error msg, GUI not set to an instance of an object. If GUI is not an object, how are you going to call on it's member variable/methods?

What Ian was telling you to do is declare and initialize your GUI. (alright, the syntax will be java, but it's close to C# i think you'll undertand)
Code:
public class test{
    UserDefinedClass GUI = null;

    ...
    ...  //somewhere in the class before GUI has been called, you need to perform
    GUI = new UserDefinedClass();
    ...

    public static void Write(String x){...} // where your error occurred

    public static void WriteLine( ... ){...}
}//end of class defn
if you have an object that you will be assigning reference to, i personally suggest declare it and initialize to null, and you can check if your object is null at any time to make sure things are on the right track
03/17/2011 17:50 Ian*#10
well stefan if your methods are static you dont have to initialize it, but in this case I dont think they are if you're just using your gui's properties that visual studios gives you. so you have to initialize it.

Some info on msdn.

[Only registered and activated users can see links. Click Here To Register...]
03/20/2011 21:56 TomasLT#11
And start reading what your ide offering u. First troubleshooting tip:

YourClassName GUI = new YourClassName();
03/21/2011 16:03 iStefan#12
But I am initializing it when it starts..
Code:
   GUI = new iGUI();
            Application.Run(GUI);
03/21/2011 17:32 shitboi#13
it's better off that you load your entire code up here so that others can help you.