Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

receiving NullPointerException

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting the following exception :
Exception occurred during event dispatching:
java.lang.NullPointerException
at PaneDemo4.populate_cards(PaneDemo4.java:356)
at get_cards_details.Employee(get_cards_details.java:72)
at get_cards_details.<init>(get_cards_details.java:12)
at PaneDemo4$3.actionPerformed(PaneDemo4.java:290)
at javax.swing.JComboBox.fireActionEvent(JComboBox.java:870)
at javax.swing.JComboBox.setSelectedItem(JComboBox.java:417)
at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:455)
at javax.swing.plaf.basic.BasicComboPopup$ListMouseHandler.mouseR

I have the following code:
// GLOBALLY DECLARED IN THE CLASS ITSELF
JTextField cardsAttribNames[]
= new JTextField[13];
String str[]={"A","B","C","D"};
JTextField cardsTextField[][]
= new JTextField[13];
.
.
.
.
.
.
.
. // WITHIN A FUNCTION
for(int k=0;k<13;k++)
{
attribPanel.setLayout(new GridLayout(0,12));
cardsAttribNames[k] = new JTextField(10);
cardsAttribNames[k].setBackground(Color.cyan);
cardsAttribNames[k].setEditable(false);
attribPanel.add(cardsAttribNames[k]);
}
.
.
.
.
.
. // WITHIN A FUNCTION
for(int i=0;i<13;i++)
{
for(int j=0;j<13;j++)
{
comm_ports.setLayout(new GridLayout(12,12));
cardsTextField[i][j] = new JTextField(10);
comm_ports.add(cardsTextField[i][j]);
}
}
I am getting the following error when I try to
setText for the JTextFields as follows :
// WITHIN A FUNCTION(Have passed JTextFields as a parameter)

cardsAttribNames[0].setText(str[0]);
OR
cardsTextField[0][0].setText(str[0]);
Exception occurred during event dispatching:
java.lang.NullPointerException
at PaneDemo4.populate_cards(PaneDemo4.java:356)
at get_cards_details.Employee(get_cards_details.java:72)
at get_cards_details.<init>(get_cards_details.java:12)
at PaneDemo4$3.actionPerformed(PaneDemo4.java:290)
at javax.swing.JComboBox.fireActionEvent(JComboBox.java:870)
at javax.swing.JComboBox.setSelectedItem(JComboBox.java:417)
at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:455)
at javax.swing.plaf.basic.BasicComboPopup$ListMouseHandler.mouseR
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sharath kv, would you please change your displayed name according to the JavaRanch Naming Policy.
- Thanks Barry.
 
No more fooling around. Read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic