Results 1 to 11 of 11
Thread: check this out
- 07-21-2011, 02:51 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 6
- Rep Power
- 0
check this out
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at SwingTutorialPackage.SamplePanel.createEntryFields (SamplePanel.java:124)
at SwingTutorialPackage.SamplePanel.<init>(SamplePane l.java:27)
at SwingTutorialPackage.SamplePanel.createAndShowGUI( SamplePanel.java:150)
at SwingTutorialPackage.SamplePanel.access$0(SamplePa nel.java:144)
at SwingTutorialPackage.SamplePanel$2.run(SamplePanel .java:163)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
getting this error help me out
below is the code for the generated error
Java Code:package SwingTutorialPackage; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; public class SamplePanel extends JPanel implements ActionListener,FocusListener { JTextField Name,JDBCDriver,JDBCURL,ServerAddress,Database,Use rname,Password; Font regularFont, italicFont; final static int GAP = 1; public SamplePanel() { setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); JPanel testpanel = new JPanel(){ //Don't allow us to stretch vertically. public Dimension getMaximumSize() { Dimension pref = getPreferredSize(); return new Dimension(Integer.MAX_VALUE, pref.height); } };; testpanel.setLayout(new BoxLayout(testpanel, BoxLayout.PAGE_AXIS)); testpanel.add(createEntryFields()); testpanel.add(createButtons());} protected JComponent createButtons() { JPanel panel = new JPanel(new FlowLayout(FlowLayout.TRAILING)); JButton button = new JButton("Wizard"); button.addActionListener(this); button.setActionCommand("wizard"); panel.add(button); button = new JButton("Test"); button.addActionListener(this); button.setActionCommand("Test"); panel.add(button); button = new JButton("Save"); button.addActionListener(this); button.setActionCommand("Save"); panel.add(button); button = new JButton("Cancel"); button.addActionListener(this); button.setActionCommand("Cancel"); panel.add(button); panel.setBorder(BorderFactory.createEmptyBorder(0, 0, GAP-5, GAP-5)); return panel; } public void actionPerformed(ActionEvent e) { if ("wizard".equals(e.getActionCommand())) { Name.setText(""); }else { JDBCDriver.setText(""); } } public void focusGained(FocusEvent e) { Component c = e.getComponent(); if(c instanceof JTextField) { ((JTextField)c).selectAll(); } } //Needed for FocusListener interface. public void focusLost(FocusEvent e) { } //ignore protected JComponent createEntryFields() { JPanel panel = new JPanel(new SpringLayout()); String[] labelStrings = { "Name: ", "JDBC Driver: ", "JDBC URL: ", "Server Address: ", "Database:", "Username:", "Password:", }; JLabel[] labels = new JLabel[labelStrings.length]; JComponent[] fields = new JComponent[labelStrings.length]; int fieldNum = 0; //Create the text field and set it up. Name = new JTextField(); Name.setColumns(20); fields[fieldNum++] = Name; JDBCDriver = new JTextField(); JDBCDriver.setColumns(20); fields[fieldNum++] = JDBCDriver; JDBCURL = new JTextField(); JDBCURL.setColumns(20); fields[fieldNum++] = JDBCURL; ServerAddress = new JTextField(); ServerAddress.setColumns(20); fields[fieldNum++] = ServerAddress; Database = new JTextField(); Database.setColumns(20); fields[fieldNum++] = Database; //Associate label/field pairs, add everything, //and lay it out. for (int i = 0; i < labelStrings.length; i++) { labels[i] = new JLabel(labelStrings[i], JLabel.TRAILING); labels[i].setLabelFor(fields[i]); panel.add(labels[i]); panel.add(fields[i]); //Add listeners to each field. JTextField tf = null; tf=(JTextField)fields[i]; tf.addActionListener(this); tf.addFocusListener(this); } SpringUtilities.makeCompactGrid(panel, labelStrings.length, 2, GAP, GAP, //init x,y GAP, GAP/2);//xpad, ypad return panel; } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event dispatch thread. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("WelcomePage"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E); //Add contents to the window. frame.add(new SamplePanel()); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event dispatch thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { //Turn off metal's use of bold fonts UIManager.put("swing.boldMetal", Boolean.FALSE); createAndShowGUI(); } });} }Last edited by RajeshReddy; 07-22-2011 at 07:10 AM.
- 07-21-2011, 02:57 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Where is line 124, and please use code tags when posting code.
- 07-21-2011, 03:28 PM #3
Is there a reason you've posted this question three times, each with a different uninformative title?
Please see the link in my signature on asking smart questions.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 07-21-2011, 03:33 PM #4
You should test that fieldNum == labelStrings.length
- 07-21-2011, 03:35 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
@OP: I closed your other two identical threads.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-22-2011, 07:21 AM #6
Member
- Join Date
- Jul 2011
- Posts
- 6
- Rep Power
- 0
now please check out
- 07-22-2011, 07:21 AM #7
Member
- Join Date
- Jul 2011
- Posts
- 6
- Rep Power
- 0
can u be clear,there's no such fieldNum == labelStrings.length
- 07-22-2011, 07:27 AM #8
I checked it out and wasn't impressed. Next!
- 07-22-2011, 01:32 PM #9
What is the value of fieldNum?
How many elements are there in the labelStrings array?
- 07-25-2011, 11:15 AM #10
Member
- Join Date
- Jul 2011
- Posts
- 6
- Rep Power
- 0
- 07-25-2011, 12:28 PM #11
Similar Threads
-
Can someone check this over?
By Phyxed in forum New To JavaReplies: 2Last Post: 03-29-2011, 09:07 AM -
Don't know what to check for
By Chasingxsuns in forum New To JavaReplies: 8Last Post: 08-26-2009, 05:59 AM -
pls check it
By aRTx in forum New To JavaReplies: 0Last Post: 03-24-2009, 02:35 PM -
Check for null int
By SnarfSnarf in forum New To JavaReplies: 5Last Post: 01-30-2009, 11:12 PM -
Check box tag
By elizaabru in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-26-2008, 02:37 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks