Results 1 to 11 of 11

Thread: [RESOLVED] [2005] Default Splash Screen Exception

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Resolved [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?

  2. #2
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    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.
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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:
    1. Public Class Form1
    2.  
    3.     Private someVar As String = Me.TextBox1.Text
    4.  
    5. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    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.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by maps; Sep 14th, 2006 at 08:59 AM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    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.
    Attached Files Attached Files

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    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!

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    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.

Posting Permissions

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



Click Here to Expand Forum to Full Width