CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2010
    Posts
    121

    getText and java.lang.NullPointerException

    I have a database connection which works well when using static final Strings, i.e. DATABASE_NAME = "test";

    I want to make this a little more dynamic so I created a text box on my JFrame

    Code:
    		txtDBName = new JTextField();
    		txtDBName.setText("");
    Then I created a method to return the String of txtDBName as follows:

    Code:
        public String getDatabaseName() 
        { 
              return txtDBName.getText().trim(); 
        }
    I then want to use the value in txtDBName as the name of my database in my connection string as follows:

    Code:
    conn=DriverManager.getConnection(dbView.DATABASE_URL + dbView.getDatabaseName() , username, password);
    I also tried the following without any luck

    Code:
    conn=DriverManager.getConnection(dbView.DATABASE_URL + dbView.txtDBName.getText(), username, password);
    but I keep getting a nullPointerException

    Can someone shed some light on this for me?

    Thanks

  2. #2
    Join Date
    Feb 2010
    Posts
    121

    Re: getText and java.lang.NullPointerException

    It's okay - I figured it out. I was calling the getText value in the wrong place

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

Featured