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 8040391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:52:47+00:00 2026-06-05T03:52:47+00:00

I am developing a desktop application using Swing, but with this I want to

  • 0

I am developing a desktop application using Swing, but with this I want to use Spring framework to use IOC, and that I want to do using Interface technique. But I am getting nullPointerException when I call a function by instance of an Interface and that interface is implemented by a class in which called function is declared.

Here is my simple app code:

Interface:

public interface IEmpMasterService {    
    public InternalResultsResponse<EmpMaster> maintainEmpMaster(
            EmpMaster empMaster);
}

Implementer class:

public class EmpMasterService implements IEmpMasterService {    
    private IEmpMasterDAO empMasterDAO; 
    public IEmpMasterDAO getEmpMasterDAO() {
        return empMasterDAO;
    }
    public void setEmpMasterDAO(IEmpMasterDAO empMasterDAO) {
        this.empMasterDAO = empMasterDAO;
    }
    @Override
    public InternalResultsResponse<EmpMaster> maintainEmpMaster(
            EmpMaster empMaster) {
        InternalResultsResponse<EmpMaster> response = new InternalResultsResponse<EmpMaster>();
        //some logic her...
        response = getEmpMasterDAO().maintainEmpMaster(request);
        return response;
    }}

DAO Interface:

public interface IEmpMasterDAO {
    InternalResultsResponse<EmpMaster> maintainEmpMaster(
            EmpMasterRequest request);
}
class Implementing DAO:
public class EmpMasterDAO extends HibernateDaoSupport implements IEmpMasterDAO{
    @Override
    public InternalResultsResponse<EmpMaster> maintainEmpMaster(
            EmpMasterRequest empMasterRequest) {
//hibernate code goes here...       
        return resultsResponse;
    }
} 

Main Class:

public class EmpManager extends javax.swing.JFrame {    
    private IEmpMasterService empMasterService;
    private static ApplicationContext context;  
    public IEmpMasterService getEmpMasterService() {
        return empMasterService;
    }
    public void setEmpMasterService(IEmpMasterService empMasterService) {
        this.empMasterService = empMasterService;
    }
public static void main(String args[]) {
        context = new ClassPathXmlApplicationContext(new String[]{"ApplicationContext.xml"});
empMasterService = (EmpMasterService)context.getBean("empMasterService");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        String name = jTextField1.getText();
        String salary = jTextField2.getText();
        EmpMaster empMaster = new EmpMaster();
        empMaster.setEmpName(name);
        empMaster.setSalary(Double.parseDouble(salary));  
//***** getting Error at this line *****//    
        InternalResultsResponse<EmpMaster> response = getEmpMasterService().maintainEmpMaster(empMaster);       
    }

my ApplicationContext.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <import resource="dataSource.xml"/>
       <bean id="mainFrame" class="org.UI.EmpManager">
        <property name="title"> <value>Spring Example</value></property>    
        <property name="empMasterService" ref="empMasterServiceImpl"></property>    
    </bean>     
    <bean id="empMasterServiceImpl" class="org.service.EmpMasterService">
        <property name="empMasterDAO" ref="empMasterDAOTarget"></property>      
    </bean> 
    <bean id="empMasterDAOTarget" class="org.DAO.EmpMasterDAO">
        <property name="hibernateTemplate" ref="matrixHibernateTemplate"/>
    </bean> 
</beans>

And when i click on button an error that i am getting.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at org.UI.EmpManager.jButton1ActionPerformed(EmpManager.java:140)
    at org.UI.EmpManager.access$0(EmpManager.java:132)
    at org.UI.EmpManager$1.actionPerformed(EmpManager.java:67)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
  • 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-05T03:52:48+00:00Added an answer on June 5, 2026 at 3:52 am

    How are you creating EmpManager, there is a bean in your application xml for the manager, but it also contains your main method. Then within your main method you’re getting the application context, and setting the service bean, so your EmpManager bean is not doing anything in your application context.

    I’d recommend extracting the main method into a different class in which you load the Application Context and use getBean only on the UI manager. The way you currently have it set up ignores a lot of the IoC capabilities of Spring by directly grabbing beans from the Application Context, rather than letting Spring do that for you.

    This might not solve your problem directly, but it will at least allow Spring to have a single point of entry, and keep DI in the hands of Spring, rather than relying on you to set them yourself.

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

Sidebar

Related Questions

We are developing a desktop application using Java Swing that requires to show width
I am developing desktop GUI application using java swing. And I want to show
I am developing a desktop app using Java and Swing Application Framework. I have
We have a dilemma; developing desktop application using Matisse or Jigloo.. Matisse has this
I am developing a Java Desktop Application and want a light database that can
Im developing desktop java application using maven. I got a *.properties file that I
I am developing a desktop application using pyside(qt), I want to access(iterate) all line
i am developing a desktop application using java. this application is for school kid
I am developing an application using Zend Framework 1.11.10. I have used this article
I'm developing a desktop application in Java, and I want to use vaadin as

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.