Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7770197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:21:00+00:00 2026-06-01T16:21:00+00:00

3rd Code Sample contains the error – how to solve? In the following code

  • 0

3rd Code Sample contains the error – how to solve?

In the following code I have generated a method called “generator”.
This method receives a JTextField and a JLabel as parameter.

It generates individual JPanels and adds them onto another JPanel (the one with the Border “Vermieter”).
The result should look like this (marked red):

http://imageshack.us/photo/my-images/853/stammdateneraffsenguibe.png/

here I am instantiating the the JTextFields as fields:

private JTextField txtplzvermieter;
private JTextField txtemailvermieter;
private JTextField txtgeburtsdatumvermieter;
private JTextField txthandyvermieter;
private JTextField txtidvermieter;
private JTextField txtnamevermieter;
private JTextField txtortvermieter;
private JTextField txtstrassevermieter;
private JTextField txttelefonvermieter;
private JTextField txtvornamevermieter;

here I am calling my methode which I described above

        public  void vermieterPanel(JPanel verPanel){
         verPanel.add(generator( "ID", txtidvermieter ));
       verPanel.add(generator("Name", txtnamevermieter ));
       verPanel.add(generator( "Vorname", txtvornamevermieter ));
       verPanel.add(generator( "Straße", txtstrassevermieter ));
       verPanel.add(generator("PLZ", txtplzvermieter ));
       verPanel.add(generator( "Ort", txtortvermieter ));
       verPanel.add(generator( "Geburtsdatum", txtgeburtsdatumvermieter ));
       verPanel.add(generator( "Telefon", txttelefonvermieter ));
       verPanel.add(generator("Handy", txthandyvermieter ));
       verPanel.add(generator( "E-Mail", txtemailvermieter ));

and here is the methode generator which contains the error:

      public JPanel generator(String lableText, JTextField s){   // generiert ein Panel mit einer Zeile aus lable + TextFeld

     JPanel gens = new JPanel();
     JLabel lable = new JLabel(lableText);
     lable.setPreferredSize(new Dimension(100,25));

     s = new JTextField();
     s.setPreferredSize(new Dimension(200, 25));


    gens.add(lable);
    gens.add(s);
    return gens;
  }

later I can’t get a reference on my TeftFields with .getText(); because I have created a reference onto a new JTextField-Object here s = new JTextField();

If I remove the line in order to access my Objects I get a Null-Pointer exception.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:21:02+00:00Added an answer on June 1, 2026 at 4:21 pm

    Of course you will get an exception, because you are passing the JTextield before you initialize it!!
    you are just declaring it,
    initialize it with the new keyword before passing it as parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading some 3rd party code and I found this: x.Flags = x.Flags
This is driving me nuts. I am using some 3rd-party code in a Windows
I recently ran across some 3rd party C# code which does the following: public
I have a really large VB6 code base with a ton of 3rd party
Based on PlatformLibrary sample code in the SDK, I have created a small hello
This is a sample from book Cocoa Programming For Mac Os X 3rd(HD) chapter
RetainAll method function is in java what is alternative method in objective-C sample code
pls advise why this happens. on a simple sample server app i have the
Here’s the situation: We have a 3rd party application that intermittently displays an error
Problem The basic problem is I want to debug some 3rd party code to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.