This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes receiving NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "receiving NullPointerException " Watch "receiving NullPointerException " New topic
Author

receiving NullPointerException

sharath kv
Greenhorn

Joined: May 06, 2003
Posts: 20
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

Joined: Aug 03, 2002
Posts: 7729
Sharath kv, would you please change your displayed name according to the JavaRanch Naming Policy.
- Thanks Barry.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: receiving NullPointerException