[RESOLVED] [2005] Default Splash Screen Exception
I had never used the default splash screen in 2005 before but here i go and i get an exception "Object reference not set to an instance of an object." WHY!
I just create a new application, create a new form (frmMain) and i make it my startup.
Then i create a new form(the default splash Screen in the IDE) and make it my splash screen in the application properties.
I Build succesfuly and then run the application. Well at this point the splash screen shows but while it closes, i expect the startup form(frmMain) to simply show...but i get this exception. Damn, i cant even find an answer anywhere.
Has someone gotten into this before?
Re: [2005] Default Splash Screen Exception
My guess is that when you try to close the splash form, the main form has not been initialised. At this point, the program tries to close or open the main form (I'm guessing here), and that generates the exception. The fix I'd suggest is adding Form1.Show to the closing and/or visibilitychanged events of your splashscreen.
Re: [2005] Default Splash Screen Exception
I am not closing the splash form any where. It was predesigned to close by itself.I dont know..the closing code must be hiding somewhere.
Even if i add frmMain.Show in the formClosing event, it gives the same exception.
Re: [2005] Default Splash Screen Exception
When you use the spalsh screen functionality built into VB 2005 it's all taken care of for you. The spalsh screen is created and displayed on a different thread that is completely controlled by the application framework. If you're getting that exception I'll wager that it's because you've messed up code in your main form, probably access a property of a control before the call to InitializeComponent call. Do you initialise any member variables on the same line that they're declared on using a property of a control? If so then that's your culprit. Here's an example that will throw a NullReferenceException:
VB Code:
Public Class Form1
Private someVar As String = Me.TextBox1.Text
End Class
Member variable declarations are executed before the body of the constructor, so that means that that code would try to access the Text property of the TextBox before the constructor was executed. Given that the constructor calls InitializeComponent, in which the TextBox is created, the TextBox1 varoable is a null reference when the code above is executed. I'm guessing that you're doing something along those lines.
Let me reiterate: your splash screen should have no interaction with your main form whatsoever. You create a form to use as the splash screen and assign it to that property in the project properties. That's it. Everything else is done for you.
2 Attachment(s)
Re: [2005] Default Splash Screen Exception
JMC, i agree with what you have said but i cant get going.I dont really understand WHY its behaving this way.
attached is what i have. There is no code in any of the forms except the generated code by the IDE.
And the exception is below.
Re: [2005] Default Splash Screen Exception
Create a new Windows Application project. Right-click the project in the Solution Explorer and select Add New Item. Double-click the Splash Screen item. Click the Properties button at the top of the Solution Explorer. In the Splash Screen drop-down list select SplashScreen1. Run the project.
That's it. That's all you do to have your splash screen display before the main form. Note also that the Splash Screen item template has NOTHING whatsoever to do with the Splash Screen property of the project. Using the Splash Screen template does not make that form the Splash Screen for the project. It simply creates a form with some properties set and some controls added to make it appropriate in appearance to be used as a splash screen. You can assign any form you like to the Splash Screen property and you can show a form created from the Splash Screen template any time you like. The template is merely a convenience.
Re: [2005] Default Splash Screen Exception
I've looked at your project and you are obviously trying to make this more complicated than it needs to be. If you haven't already, follow the instructions in my previous post to see how easy it SHOULD be.
1 Attachment(s)
Re: [2005] Default Splash Screen Exception
Sorry, i just didnt know what to remove and what to leave.
I havent declared anything anywhere that affects any of the two forms, not even before the InitializeComponent call.
But Here you are.
Re: [2005] Default Splash Screen Exception
Now this is what i have done.
I created a new project, renamed form1 to frmMain.
Created a splashScreen from the default one, renamed it frmSplash.
Went to the Applications Tab. Set frmMain to be my startup and frmSplash to be my splash.
Now i run the project and i get the same kind of error!
Am I Dumb! or the IDE is Dumb!
Re: [2005] Default Splash Screen Exception
Remove any folders that contain binaries, which basically means obj and bin.
That project ran without issue for me.
Re: [2005] Default Splash Screen Exception
Quote:
Originally Posted by jmcilhinney
Remove any folders that contain binaries, which basically means obj and bin.
That project ran without issue for me.
100% Strange. Then my IDE is Dumb.
I think i will have to go the manual way.