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

  • SEARCH
  • Home
  • 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 8432611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:10:29+00:00 2026-06-10T06:10:29+00:00

I have built this application and I tried to run it but I could

  • 0

I have built this application and I tried to run it but I could not get the data from a JTextField. I don’t know what’s wrong… Here is the code that is relevant…

Construct the JTextFeild: (File Main.java)

public class Constructor extends javax.swing.JFrame {

   public Constructor() {
      initComponents();
   }

   private void initComponents() {    
      refernce = new javax.swing.JTextField();
      /*Some other code in here*/
   }

   private javax.swing.JTextField refernce;
      /*Some other code in here*/       
   }

Get the data from the Text Field: (File Save.java)

public class Save {

   /*Some other code in here*/

   private javax.swing.JTextField refernce;

   String refernceText = refernce.toString();

}

Error Report:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Save.<init>(Save.java:79)
at Constructor.saveMouseClicked(Constructor.java:444)
at Constructor.access$200(Constructor.java:15)
at Constructor$3.mouseClicked(Constructor.java:210)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
... (it carry on(ask if you need it))

So where have I gone wrong??? Also there are no syntax errors etc…

  • 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-10T06:10:31+00:00Added an answer on June 10, 2026 at 6:10 am

    Here is an issue,

    public class Save {
      private javax.swing.JTextField refernce; <---- ISSUE
      ...
      String refernceText = refernce.toString();  
    }
    

    reference field in class Save is initialized with null.

    You have to pass the reference of JTextField object reference of Constructor class to Save class.

    For instance,

    public class Save {
      private javax.swing.JTextField refernce;
      public Save(javax.swing.JTextField refernce){
        this.refernce=refernce;
      } 
      ...
      //and use JTextField in your methods
      void testMethod() {
        if(refernce!=null){
         String refernceText = refernce.getText();
         .....
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this $data array: (built on a shell, not a form) (debugged here)
I have this consumer targeted application that has built in error reporting. Sometimes I
I know this sounds confusing: I have just built some basic prev/next pagination for
This one is a long story: i have recently built a win32 application in
I have built this accordion using the jquery ui accordion plugin, I sort of
I have built a T-SQL query like this: DECLARE @search nvarchar(1000) = 'FORMSOF(INFLECTIONAL,hills) AND
I have a multi-step order form built in this manner: Step 1: Choose category
I have a page with an unordered list built like this: <ul id='shows'> <div
I've never done this before. The website I have just built is the second
I have an HTML table containing a few rows (this is built dynamically). All

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.