Hello, I am trying to create an MDI application and am having problems with one of the frames. Walking through the errors, the first error points to a list generated by Netbeans code that I think is the null problem. When I look further down the error list, I get to code that I have added in the main frame of the MDI. I was thinking I need to initialize this list from the MonthlyBudgetUI Frame in the MainFrame (at MainFram.<int>). But what I have tried isn't working. I have googled this error message and it seems initiliazing whatever is throwing the null exception is suppose to fix the problem. But I am not sure how to do this. Below is the error message and bits of code found in the first errors. I have another frame that is working just fine, and I created them the same way, so I don't see why I am getting the error now. Thanks in advance for your help. Also, I had tried to add a JTable at first and then deleted it. Maybe that is contributing?

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at presentation.MonthlyBudgetUI.initComponents(MonthlyBudgetUI.java:33)
    at presentation.MonthlyBudgetUI.<init>(MonthlyBudgetUI.java:17)
    at presentation.MainFrame.<init>(MainFrame.java:18)
    at presentation.MainFrame$7.run(MainFrame.java:196)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:688)
    at java.awt.EventQueue$3.run(EventQueue.java:686)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

MonthlyBudgetUI code bits:

    private void initComponents() {

     entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("Toben.v2PU").createEntityManager();
     budgetCategoryQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT b FROM BudgetCategory b");
     budgetCategoryList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : budgetCategoryQuery.getResultList();
     entityManager1 = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("Toben.v2PU").createEntityManager();
     //BELOW IS LINE 33 - first error message
     list1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : ((javax.persistence.Query)null).getResultList();
     jScrollPane1 = new javax.swing.JScrollPane();
     jList1 = new javax.swing.JList();

Main Frame code bits that i added to call the MonthlyBudgetUI frame:

     private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt){                                           
     MonthlyBudgetUI monbud = new MonthlyBudgetUI();
     desktop.add(monbud);
     monbud.setVisible(true);}

((javax.persistence.Query)null).getResultList();

What did you intend with this particular piece of syntax?

I was trying to connect a JTable to a database created in MySQL. I think that code was generated as apart of that attempt. I just deleted my frame and recreated it with a new JTable and now it works (with the database connection). I really don't know what I did wrong the first time. :( It is working now at least....

((javax.persistence.Query)null).getResultList();

starting inside the brackets you have a null reference. null
You then cast that to a javax.persistence.Query type, (javax.persistence.Query) null
but it's still null.
Then you use that to try to call getResultList(). Hey presto NPE.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.