• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

receiving NullPointerException

 
sharath kv
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sharath kv, would you please change your displayed name according to the JavaRanch Naming Policy.
- Thanks Barry.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic