Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

  1. #1
    miche26 is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Question Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    I've looked at my errors, and I am new to java so i research what some of my errors mean. the problem is that i am having a hard time figuring out how to fix the problem. Alot of the other stuff that says unknown source, I have no idea how to fix.

    Any help or pointers will be greatly appreciated.

    Here are my errors:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at CreateFile.addRecord(CreateFile.java:171)
    at CreateFile$3.actionPerformed(CreateFile.java:78)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(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)

    Here is my codes:
    1. import java.awt.*;
    2. import java.awt.BorderLayout;
    3. import java.awt.event.ActionEvent;
    4. import java.awt.event.ActionListener;
    5. import java.awt.event.WindowAdapter;
    6. import java.awt.event.WindowEvent;
    7. import java.io.File;
    8. import java.io.FileOutputStream;
    9. import java.io.IOException;
    10. import java.io.ObjectOutputStream;
    11. import javax.swing.JButton;
    12. import javax.swing.JFileChooser;
    13. import javax.swing.JFrame;
    14. import javax.swing.JOptionPane;
    15. import javax.swing.filechooser.FileNameExtensionFilter;
    16. //import javax.swing.table.*;
    17. //import jxl.*;
    18. //import jxl.write.*;
    19. public class CreateFile extends JFrame{
    20. /**
    21. *
    22. */
    23. private static final long serialVersionUID = 1L;
    24. private ObjectOutputStream output;
    25. BillingUI userInterface;
    26. private JButton enterButton, openButton, exitButton;
    27. public CreateFile() {
    28. super("Enter Productivity Infomation");
    29. userInterface = new BillingUI(6);
    30. getContentPane().add(userInterface, BorderLayout.CENTER);
    31. openButton = userInterface.task1Button();
    32. openButton.setText("save data to");
    33. openButton.addActionListener(
    34. new ActionListener(){
    35. public void actionPerformed(ActionEvent event)
    36. {
    37. openFile();
    38. }
    39. }); // end action listener
    40. exitButton = userInterface.task3Button();
    41. exitButton.setText("Cancel");
    42. exitButton.setEnabled(true);
    43. exitButton.addActionListener(
    44. new ActionListener(){
    45. public void actionPerformed(ActionEvent event)
    46. {
    47. System.exit(0);
    48. }
    49. });
    50. enterButton = userInterface.task2Button();
    51. enterButton.setText("Enter");
    52. enterButton.setEnabled(true);
    53. enterButton.addActionListener(
    54. new ActionListener(){
    55. public void actionPerformed(ActionEvent event)
    56. {
      [78] addRecord();
    57. }
    58. });
    59. addWindowListener(
    60. new WindowAdapter(){
    61. public void windowClosing(WindowEvent event)
    62. {
    63. if(output != null)
    64. addRecord();
    65. closeFile();
    66. }
    67. });
    68. setSize(300,300);
    69. setVisible(true);
    70. }
    71. void openFile()
    72. {
    73. JFileChooser chooseFile = new JFileChooser();
    74. chooseFile.setFileSelectionMode(JFileChooser.FILES _ONLY);
    75. FileNameExtensionFilter filter = new FileNameExtensionFilter("txt", "dat", "xls");
    76. chooseFile.addChoosableFileFilter(filter);
    77. int result = chooseFile.showSaveDialog(this);
    78. if(result == JFileChooser.APPROVE_OPTION)
    79. return;
    80. File filename = chooseFile.getSelectedFile();
    81. if(filename == null || filename.getName().equals(" "))
    82. JOptionPane.showMessageDialog(this, "Invalid File name", "Invalid File Name", JOptionPane.ERROR_MESSAGE);
    83. else{
    84. try{
    85. output = new ObjectOutputStream( new FileOutputStream(filename));
    86. openButton.setEnabled(false);
    87. enterButton.setEnabled(true);
    88. }
    89. catch(IOException ioException){
    90. JOptionPane.showMessageDialog(this, "error opening file", "Error", JOptionPane.ERROR_MESSAGE);
    91. }
    92. }
    93. }
    94. void closeFile()
    95. {
    96. try{
    97. output.close();
    98. System.exit(0);
    99. }
    100. catch (IOException ioException){
    101. JOptionPane.showMessageDialog(this, "Error Closing file", "Error", JOptionPane.ERROR_MESSAGE);
    102. System.exit(1);
    103. }
    104. }
    105. public void addRecord()
    106. {
    107. int enternumber =0;
    108. TimeLog record;
    109. String fieldValues[] = userInterface.getFieldValues();
    110. if(!fieldValues[BillingUI.ENTERTOTAL].equals("")){
    111. try{
    112. enternumber = Integer.parseInt(fieldValues[BillingUI.ENTERTOTAL]);
    113. if (enternumber > 0) {
    114. record = new TimeLog(fieldValues[BillingUI.TASKNAME],fieldValues[BillingUI.DATE], fieldValues[BillingUI.TIMESTART],
    115. fieldValues[BillingUI.TIMESTOP], enternumber, fieldValues[BillingUI.YOURNOTES] );

    116. [171] output.writeObject(record);
    117. output.flush();
    118. }
    119. else{
    120. JOptionPane.showInputDialog(this, "total field must be an integer", JOptionPane.ERROR_MESSAGE);
    121. }
    122. userInterface.clearFields();
    123. } // end try else block
    124. catch(NumberFormatException | IOException formatException){
    125. JOptionPane.showMessageDialog(this, "bad number dude", "invalid format/n must be integer greater than 0",
    126. JOptionPane.ERROR_MESSAGE);
    127. closeFile();
    128. }
    129. } // end if
    130. }
    131. public static void main(String args[])
    132. {
    133. new CreateFile();
    134. }
    135. }


    import java.io.Serializable;
    //import java.util.*;

    public class TimeLog implements Serializable{

    /**
    *
    */
    private static final long serialVersionUID = 1L;
    private String TASKNAME;
    private String DATE;
    private String TIMESTART,TIMESTOP;
    private int ENTERTOTAL;
    private String YOURNOTES;

    public TimeLog(){
    this(" ", " "," "," ",0," ");
    }

    public TimeLog(String TASKNAME,
    String DATE,
    String TIMESTART,
    String TIMESTOP,
    int ENTERTOTAL,
    String YOURNOTES)

    {
    setTASKNAME(TASKNAME);
    setDATE(DATE);
    setTIMESTART(TIMESTART);
    setTIMESTOP(TIMESTOP);
    setENTERTOTAL (ENTERTOTAL);
    setYOURNOTES(YOURNOTES);
    }


    // task name
    public void setTASKNAME(String tasknm)
    {
    TASKNAME = tasknm;
    }

    public String getTASKNAME()
    {
    return TASKNAME;
    }
    //date
    public void setDATE(String date)
    {
    DATE = date;
    }
    public String getdate()
    {
    return DATE;
    }

    public void setTIMESTART(String time)
    {
    this.TIMESTART = time;
    }
    public String getTIMESTART()
    {
    return TIMESTART;
    }
    //time
    public void setTIMESTOP(String time)
    {
    TIMESTOP = time;
    }
    public String gettime()
    {
    return TIMESTOP;
    }
    //enter total
    public void setENTERTOTAL(int total)
    {
    ENTERTOTAL = total;
    }

    public int getENTERTOTAL()
    {
    return ENTERTOTAL;
    }
    //your notes

    public void setYOURNOTES(String notes)
    {
    YOURNOTES = notes;
    }

    public String getYOURNOTES()
    {
    return YOURNOTES;
    }

    }
    ------------------------------------------------------------------------
    import java.awt.BorderLayout;
    import java.awt.GridLayout;

    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;


    public class BillingUI extends JPanel {

    /**
    *
    */
    private static final long serialVersionUID = 1L;

    protected final static String names[] = {"Taskname","date", "Timestart", "timestop", "Entertotal", "YourNotes"};

    protected JLabel labels[];
    protected JTextField fields[];
    protected JButton dotask1, dotask2, dotask3;
    protected JPanel innerPanelCenter, innerPanelSouth;

    protected int size;

    public static final int TASKNAME = 0, DATE = 1, TIMESTART =2, TIMESTOP = 3, ENTERTOTAL =4, YOURNOTES = 5 ;

    public BillingUI(int mySize) {
    size = mySize;
    labels = new JLabel[size];
    fields = new JTextField[size];

    for (int count = 0; count < labels.length; count++)
    labels[count] = new JLabel(names[count]);

    for(int count = 0; count< fields.length; count++)
    fields[count] = new JTextField();

    innerPanelCenter = new JPanel();
    innerPanelCenter.setLayout(new GridLayout(size, 3));

    for (int count = 0; count < size; count++){
    innerPanelCenter.add(labels[count]);
    innerPanelCenter.add(fields[count]);

    }

    dotask1 = new JButton();
    dotask2 = new JButton();
    dotask3 = new JButton();

    innerPanelSouth = new JPanel();
    innerPanelSouth.add(dotask1);
    innerPanelSouth.add(dotask2);
    innerPanelSouth.add(dotask3);

    setLayout(new BorderLayout());
    add(innerPanelCenter, BorderLayout.CENTER);
    add(innerPanelSouth, BorderLayout.SOUTH);

    validate();


    }

    public JButton task1Button()
    {
    return dotask1;
    }

    public JButton task2Button()
    {
    return dotask2;
    }

    public JButton task3Button()
    {
    return dotask3;
    }

    public JTextField[] getfields()
    {
    return fields;
    }

    public void clearFields()
    {
    for(int count = 0; count < size; count++)
    fields[count].setText(" ");
    }

    public void setFieldValues(String strings[])
    throws IllegalArgumentException
    {
    if (strings.length != size)
    throw new IllegalArgumentException("There must be" + size + " Characters");

    for(int count= 0; count < size; count++ )
    fields[count].setText(strings[count]);
    }

    public String[] getFieldValues()
    {
    String[] values = new String[size];
    for(int count =0; count< size; count++)
    values[count] = fields[count].getText();


    return values;
    }
    }

  2. #2
    miche26 is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    sorry, I just realized that I was only supposed to post the code that I think is causing the error; see below. Again any help/pointers are welcomed.
    I am new to java and only have taken a basic java class

    public void addRecord()
    {
    int enternumber =0;
    TimeLog record;
    String fieldValues[] = userInterface.getFieldValues();
    if(!fieldValues[BillingUI.ENTERTOTAL].equals("")){
    try{
    enternumber = Integer.parseInt(fieldValues[BillingUI.ENTERTOTAL]);
    if (enternumber > 0) {
    record = new TimeLog(fieldValues[BillingUI.TASKNAME],fieldValues[BillingUI.DATE], fieldValues[BillingUI.TIMESTART],
    fieldValues[BillingUI.TIMESTOP], enternumber, fieldValues[BillingUI.YOURNOTES] );

    [171] output.writeObject(record);
    output.flush();
    }
    else{
    JOptionPane.showInputDialog(this, "total field must be an integer", JOptionPane.ERROR_MESSAGE);
    }
    userInterface.clearFields();
    } // end try else block
    catch(NumberFormatException | IOException formatException){
    JOptionPane.showMessageDialog(this, "bad number dude", "invalid format/n must be integer greater than 0",
    JOptionPane.ERROR_MESSAGE);
    closeFile();
    }
    } // end if

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    You'll want to get rid of the line numbers that are with part of your code, and instead post your code surrounded by [code] [/code] tags. Indicate the offending lines by comments. Also tell us what happens that brings on this error. Are you trying to add a record before you've opened a file?

  4. #4
    miche26 is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    sorry if you see this response twice

    I can repost the code with the tags if you like. the lines that , i think, is offending was posted separately in my second post with the addRecords method.

    the code ask the user the select a file to save to. Once the user select a file and hits enter, they can now enter their information in the JTextField. Once the user hits enter, its suppose to output the information on the file they select. (this is where i get the errors)

  5. #5
    miche26 is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    Java Code:
    import java.awt.*;
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectOutputStream;
    
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.filechooser.FileNameExtensionFilter;
    
    //import javax.swing.table.*;
    
    //import jxl.*;
    //import jxl.write.*;
    
    
    
    
    
    public class CreateFile extends JFrame{
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	private ObjectOutputStream output;
    	BillingUI userInterface;
    	private JButton enterButton, openButton, exitButton;
    	
    	public CreateFile() {
    		super("Enter Productivity Infomation");
    		
    		userInterface = new BillingUI(6);
    		getContentPane().add(userInterface, BorderLayout.CENTER);
    		
    		openButton = userInterface.task1Button();
    		openButton.setText("save data to");
    		
    		openButton.addActionListener(
    					new ActionListener(){
    			
    			public void actionPerformed(ActionEvent event)
    			{
    				openFile();
    			}
    		}); // end action listener
    		
    		exitButton = userInterface.task3Button();
    		exitButton.setText("Cancel");
    		exitButton.setEnabled(true);
    		
    		exitButton.addActionListener(
    				
    				new ActionListener(){
    					public void actionPerformed(ActionEvent event)
    					{
    						System.exit(0);
    					}
    				});
    		
    		
    		enterButton = userInterface.task2Button();
    		enterButton.setText("Enter");
    		enterButton.setEnabled(true);
    		
    		enterButton.addActionListener(
    				
    				new ActionListener(){
    					public void actionPerformed(ActionEvent event)
    					{
    						addRecord();
    					}
    				});
    		
    		addWindowListener(
    				
    				new WindowAdapter(){
    					
    					public void windowClosing(WindowEvent event)
    					{
    						if(output != null)
    							addRecord();
    						
    						closeFile();
    					}
    				});
    		
    		setSize(300,300);
    		setVisible(true);
    		
    			
    		
    	}
    	
    	void openFile()
    	{
    	
    	JFileChooser chooseFile = new JFileChooser();
    	
    	
    	chooseFile.setFileSelectionMode(JFileChooser.FILES_ONLY);
    	FileNameExtensionFilter filter = new FileNameExtensionFilter("txt", "dat", "xls");	
    	chooseFile.addChoosableFileFilter(filter);
    	
    	int result = chooseFile.showSaveDialog(this);
    	
    	if(result == JFileChooser.APPROVE_OPTION)
    		return;
    	
     File filename = chooseFile.getSelectedFile();
     
     if(filename == null || filename.getName().equals(" "))
    	 JOptionPane.showMessageDialog(this, "Invalid File name", "Invalid File Name", JOptionPane.ERROR_MESSAGE);
     
     else{
    	 try{
    		 output = new ObjectOutputStream( new FileOutputStream(filename));
    		 
    		 openButton.setEnabled(false);
    		 enterButton.setEnabled(true);
    	 }
    	 
    	catch(IOException ioException){
    		JOptionPane.showMessageDialog(this, "error opening file", "Error", JOptionPane.ERROR_MESSAGE);
    	}
     }
    }
    	void closeFile()
    	{
    		try{
    			output.close();
    			System.exit(0);
    		}
    		
    	catch (IOException ioException){
    		JOptionPane.showMessageDialog(this, "Error Closing file", "Error", JOptionPane.ERROR_MESSAGE);
    		System.exit(1);
    	}
    	}
    /*	
    	public void addRecord()
    	{
    		
    		
    		
    		
    		int enternumber =0;
    		
    		
    		TimeLog record;
    		String fieldValues[] = userInterface.getFieldValues();
    		
    		if(!fieldValues[BillingUI.ENTERTOTAL].equals("")){
    			
    			try{
    				enternumber = Integer.parseInt(fieldValues[BillingUI.ENTERTOTAL]);
    				
    				
    				if (enternumber > 0) {
    				
    					record = new TimeLog(fieldValues[BillingUI.TASKNAME],fieldValues[BillingUI.DATE], fieldValues[BillingUI.TIMESTART], 
    							fieldValues[BillingUI.TIMESTOP], enternumber, fieldValues[BillingUI.YOURNOTES] );
    					
    					output.writeObject(record);
    					output.flush();
    				}
    				else{
    					JOptionPane.showInputDialog(this, "total field must be an integer", JOptionPane.ERROR_MESSAGE);
    					
    				}
    				userInterface.clearFields();
    			} // end try else block
    			
    			catch(NumberFormatException | IOException formatException){
    				JOptionPane.showMessageDialog(this, "bad number dude", "invalid format/n must be integer greater than 0",
    						JOptionPane.ERROR_MESSAGE);
    				closeFile();
    				
    			}
    			
    			} // end if 
    		*/
    	}  
    	
    	public static void main(String args[])
    	{
    		new CreateFile();
    	} 
    }
    Class TimeLog
    Java Code:
    import java.io.Serializable;
    //import java.util.*;
    
    public class TimeLog implements Serializable{
     
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	private String TASKNAME;
    	private String DATE;
    	private String TIMESTART,TIMESTOP;
    	private int ENTERTOTAL;
    	private String YOURNOTES;
    	
    	public TimeLog(){
    		this(" ", " "," "," ",0," ");
    	}
    	
    	public TimeLog(String TASKNAME,
    			       String DATE,
    			       String TIMESTART,
    			       String TIMESTOP,
    				   int ENTERTOTAL,
    				   String YOURNOTES)
    	
    	{
    		setTASKNAME(TASKNAME);
    		setDATE(DATE);
    		setTIMESTART(TIMESTART);
    		setTIMESTOP(TIMESTOP);
    		setENTERTOTAL (ENTERTOTAL);
    		setYOURNOTES(YOURNOTES);
    	}
    	
    
    	// task name
    	public void setTASKNAME(String tasknm)
    	{
    		TASKNAME = tasknm;
    	}
    	
    	public String getTASKNAME()
    	{
    		return TASKNAME;
    	}
    	//date
    	public void setDATE(String date)
    	{
    		DATE = date;
    	}
    	public String getdate()
    	{
    		return DATE;
    	}
    	
    	public void setTIMESTART(String time)
    	{
    		this.TIMESTART = time;
    	}
    	public String getTIMESTART()
    	{
    		return TIMESTART;
    	}
    	//time
    	public void setTIMESTOP(String time)
    	{
    		TIMESTOP = time;
    	}
    	public String gettime()
    	{
    		return TIMESTOP;
    	}
    	//enter total
    	public void setENTERTOTAL(int total)
    	{
    		ENTERTOTAL = total;
    	}
    		
    	public int getENTERTOTAL()
    	{
    		return ENTERTOTAL;
    	}
    	//your notes
    	
    	public void setYOURNOTES(String notes)
    	{
    		YOURNOTES = notes;
    	}
    	
    	public String getYOURNOTES()
    	{
    		return YOURNOTES;
    	}
    	
    }
    Class BillingUI
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    
    public class BillingUI extends JPanel {
     
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    
    	protected final static String names[] = {"Taskname","date", "Timestart", "timestop", "Entertotal", "YourNotes"};
    	
    	protected JLabel labels[];
    	protected JTextField fields[];
    	protected JButton dotask1, dotask2, dotask3;
    	protected JPanel innerPanelCenter, innerPanelSouth;
    	
    	protected int size;
    	
    	public static final int TASKNAME = 0, DATE = 1, TIMESTART =2, 	TIMESTOP = 3, ENTERTOTAL =4,  YOURNOTES = 5 ;
    	
    	public BillingUI(int mySize) {
    		size = mySize;
    		labels = new JLabel[size];
    		fields = new JTextField[size];
    		
    		for (int count = 0; count < labels.length; count++)
    			labels[count] = new JLabel(names[count]);
    		
    		for(int count = 0; count< fields.length; count++)
    			fields[count] = new JTextField();
    		
    		innerPanelCenter = new JPanel();
    		innerPanelCenter.setLayout(new GridLayout(size, 3));
    		
    		for (int count = 0; count < size; count++){
    			innerPanelCenter.add(labels[count]);
    			innerPanelCenter.add(fields[count]);
    			
    		}
    		
    		dotask1 = new JButton();
    		dotask2 = new JButton();
    		dotask3 = new JButton();
    		
    		innerPanelSouth = new JPanel();
    		innerPanelSouth.add(dotask1);
    		innerPanelSouth.add(dotask2);
    		innerPanelSouth.add(dotask3);
    		
    		setLayout(new BorderLayout());
    		add(innerPanelCenter, BorderLayout.CENTER);
    		add(innerPanelSouth, BorderLayout.SOUTH);
    		
    		validate();
    		
    		
    	}
    	
    	public JButton task1Button()
    	{
    		return dotask1;
    	}
    	
    	public JButton task2Button()
    	{
    		return dotask2;
    	}
    	
    	public JButton task3Button()
    	{
    		return dotask3;
    	}
    	
    	public JTextField[] getfields()
    	{
    		return fields;
    	}
    	
    	public void clearFields()
    	{
    		for(int count = 0; count < size; count++)
    			fields[count].setText(" ");
    	}
    	
    	public void setFieldValues(String strings[])
    	throws IllegalArgumentException
    	{
    		if (strings.length != size)
    			throw new IllegalArgumentException("There must be" + size + " Characters");
    		
    		for(int count= 0; count < size; count++ )
    			fields[count].setText(strings[count]);
    	}
    	
    	public String[] getFieldValues()
    	{
    		String[] values = new String[size];
    		for(int count =0; count< size; count++)
    			values[count] = fields[count].getText();
    			
    			
    			return values;
    	}
    }

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    This may be causing problems:

    Java Code:
       void openFile() {
          JFileChooser chooseFile = new JFileChooser();
    
          // ....
    
          int result = chooseFile.showSaveDialog(this);
          if (result == JFileChooser.APPROVE_OPTION)
             return;  // ****************** !!!!!!!!!!!!!!
    miche26 likes this.

  7. #7
    miche26 is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    OMG YOU ARE RIGHT. ITS Suppose to be cancel option instead of approve option. It looks like gibberish in the text file though. is it suppose to look like that?

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    Quote Originally Posted by miche26 View Post
    OMG YOU ARE RIGHT. ITS Suppose to be cancel option instead of approve option. It looks like gibberish in the text file though. is it suppose to look like that?
    There's a bug in the forum software. Sorry.

  9. #9
    miche26 is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    i looked at my code for 1 1/2 days. you are amazing!!!

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    But more important than my solution, you must learn *how* I solved it, and it really isn't rocket science. I figured that output must be null, and then backtracked to where it was supposed to be created, and then sprinkled a bunch of println(...) statements in that portion of the code. When I saw that println's weren't printing their text, I knew that something halted execution in the method that is supposed to create the file. This is nothing more than brainless drudge work, but often it works.

  11. #11
    miche26 is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    how can i get it to display in english in the text file. or can I only use a dat file to output the information

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    Quote Originally Posted by miche26 View Post
    how can i get it to display in english in the text file. or can I only use a dat file to output the information
    You are using an ObjectOutputStream and serialization to record your data to disk, and this will write the information in non-human readable binary format. If you want to reclaim the data, you can do this by using an ObjectInputStream and serialization to read the information back in.

    If on the other hand you wish to write the data as human readable text, then you have several options including a BufferedWriter or PrintWriter wrapped around a FileWriter or a PrintStream object wrapped around a File. This would be more difficult to read back in though. Another option is to read and write to XML using JAXB, one I've used for set-up files.

Similar Threads

  1. Replies: 1
    Last Post: 12-13-2010, 04:19 PM
  2. Replies: 1
    Last Post: 08-20-2010, 11:42 AM
  3. Replies: 3
    Last Post: 04-30-2010, 08:44 PM
  4. Replies: 5
    Last Post: 08-26-2009, 12:37 PM
  5. Replies: 3
    Last Post: 01-29-2008, 02:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •