Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default Need help with a lot of code please.

    Hey, can anyone see why this class is causing a null pointer exception?

    Java Code:
    package HouseHockey;
    
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.ObjectOutputStream;
    import java.io.PrintWriter;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    
    public class ErrorMessages {
    	
    	JLabel label = new JLabel();
    	final JFrame frame = new JFrame("Error");
    	JPanel panel = new JPanel();
    	JButton Yes1 = new JButton("Yes");
    	JButton No1 = new JButton("No");
    	JButton Yes2 = new JButton("Yes");
    	JButton close = new JButton("Ok");
    	JButton Yes4 = new JButton("Yes");
    	JButton No2 = new JButton("No");
    	String house2;
    	Statistics g;
    	private File file = new File("/Users/eric.manget/Desktop/Scores.txt");
    	private FileWriter outFile;
    	private PrintWriter out = new PrintWriter(outFile);
    	int martlands = 0;
    	int scaddings = 0;
    	int mchughs = 0;
    	int mowbray = 0;
    	int orrs = 0;
    	int brem = 0;
    	int jacksons = 0;
    	int howards = 0;
    	
    	
    	public ErrorMessages(final JFrame frame2){
    
    		panel.add(label);
    		frame.add(panel);
    		frame.setSize(300,65);
    		frame.setVisible(true);
    		frame.setResizable(false);
    		try {
    			out = new PrintWriter(outFile);
    			outFile = new FileWriter(file);
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	
    	
    		close.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    				
    				frame.dispose();
    				
    			}
    		});
    		
    		Yes1.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				System.exit(0);
    				
    			}
    
    		});
    		
    		Yes2.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				new MainPage();
    				frame.dispose();
    				frame2.dispose();
    				
    				
    			}
    
    		});
    		
    		No1.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				frame.dispose();
    				
    			}
    
    		});
    
    		No2.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				frame.dispose();
    				
    			}
    
    		});
    		
    	}
    	
    	public void housesSame(){
    		
    		label.setText("Error: Houses must be different.");
    		panel.add(close);
    		
    	}
    	
    	public void addingplayer(){
    		
    		label.setText("Error: Player being added is not in team.");
    		frame.setSize(350,65);
    		panel.add(close);
    		
    	}
    	
    	public void unsavedData(){
    		
    	
    		label.setText("If you exit you will lose all unsaved data. Proceed?");
    		panel.add(Yes1);
    		panel.add(No1);
    		frame.setSize(390,80);
    		
    	}
    	
    	public void navMain(){
    		
    		label.setText("If you navigate to main you will lose all unsaved data. Proceed?");
    		panel.add(Yes2);
    		panel.add(No1);
    		frame.setSize(420,85);
    		
    		
    	}
    	
    	public void notEnoughPlayers(final String house,final String house2){
    		
    		label.setText("There are not enough players playing for " + house + "." + " Is this a default loss for " + house + "?" );
    		panel.add(Yes4,BorderLayout.SOUTH);
    		panel.add(No2,BorderLayout.SOUTH);
    		
    		if(house.equals("Orr's")){
    			frame.setSize(540,100);
    		}
    		else{
    			frame.setSize(620,100);
    		}
    		
    		Yes4.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				
    					
    			if(house.equals("Bremner's")){
    
    					brem = brem - 2;
    					System.out.println(brem);
    					out.write(brem - 2);
    					out.close();
    				
    			}
    			
    			if(house.equals("Orr's")){
    
    				out.write(orrs - 2);
    				out.close();
    			
    		}
    		
    			if(house.equals("Scadding's")){
    
    				out.write(scaddings - 2);
    				out.close();
    			
    		}
    			
    			if(house.equals("Mowbray's")){
    
    				out.write(mowbray - 2);
    				out.close();
    		}
    			
    			if(house.equals("Jackson's")){
    
    				out.write(jacksons - 2);
    				out.close();
    		}
    			
    			if(house.equals("Howard's")){
    
    				out.write(howards - 2);
    				out.close();
    		}
    			if(house.equals("McHugh's")){
    
    				out.write(mchughs - 2);
    				out.close();
    		}
    			if(house.equals("Martland's")){
    
    				out.write(martlands - 2);
    				out.close();
    		}
    
    			if(house2.equals("Bremner's")){
    
    				out.write(brem + 2);
    				out.close();
    			
    		}
    		
    		if(house2.equals("Orr's")){
    
    			out.write(orrs + 2);
    			out.close();
    		
    	}
    	
    		if(house2.equals("Scadding's")){
    
    			out.write(scaddings + 2);
    			out.close();
    		
    	}
    		
    		if(house2.equals("Mowbray's")){
    
    			out.write(mowbray + 2);
    			out.close();
    	}
    		
    		if(house2.equals("Jackson's")){
    
    			out.write(jacksons + 2);
    			out.close();
    	}
    		
    		if(house2.equals("Howard's")){
    
    			out.write(howards + 2);
    			out.close();
    	}
    		if(house2.equals("McHugh's")){
    
    			out.write(mchughs + 2);
    			out.close();
    	}
    		if(house2.equals("Martland's")){
    
    			out.write(martlands + 2);
    			out.close();
    	}
    				
    		
    				
    			}
    
    		});
    		
    	}
    
    	public void noPDF(){
    		
    		label.setText("Error: PDF not found..." );
    		panel.add(close);
    		
    		
    	}
    	
    	public Integer getHousePoints(String house) {
    
    		if (house.equals("Bremner's")) {
    
    			return brem;
    
    		}
    		if (house.equals("Scadding's")) {
    
    			return scaddings;
    
    		}
    		if (house.equals("Orr's")) {
    
    			return orrs;
    
    		}
    		if (house.equals("Jackson's")) {
    
    			return jacksons;
    
    		}
    		if (house.equals("Mowbray's")) {
    
    			return mowbray;
    
    		}
    		if (house.equals("Howard's")) {
    
    			return howards;
    
    		}
    		if (house.equals("McHugh's")) {
    
    			return mchughs;
    
    		}
    		if (house.equals("Martland's")) {
    
    			return martlands;
    
    		} else {
    			return null;
    		}
    	
    	
    	}
    }


    My next class that is accessing the integers.



    Java Code:
    package HouseHockey;
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.RowFilter;
    import javax.swing.table.TableRowSorter;
    
    public class Statistics {
    
    	JPanel panel = new JPanel();
    	static JTable table;
    	JScrollPane scrollPane;
    	static Integer BremP;
    	Integer ScadP;
    	Integer OrrP;
    	Integer JackP;
    	Integer MowP;
    	Integer HowP;
    	Integer McHP;
    	Integer MartP;
    	String Brem = "Bremner's";
    	String Scad = "Scadding's";
    	String Orr = "Orr's";
    	String Jack = "Jackson's";
    	String Mow = "Mowbray's";
    	String How = "Howard's";
    	String McH = "McHugh's";
    	String Mart = "Martland's";
    	JFrame frame = new JFrame("Statistics");
    	JFrame fram = new JFrame();
    	ErrorMessages msg = new ErrorMessages(fram);
    	public Statistics() {
    
    		
    		Integer BremP = msg.getHousePoints("Bremner's");
    		Integer ScadP = msg.getHousePoints("Scadding's");
    		Integer OrrP = msg.getHousePoints("Orr's");
    		Integer JackP = msg.getHousePoints("McHugh's");
    		Integer MowP = msg.getHousePoints("Jackson's");
    		Integer HowP = msg.getHousePoints("Mowbray's");
    		Integer McHP = msg.getHousePoints("Martland's");
    		Integer MartP = msg.getHousePoints("Howard's");
    		System.out.println(msg.getHousePoints("Bremner's"));
    		fram.dispose();
    		
    		String columnNames[] = { "Houses", "Points" };
    
    		Object dataValues[][] = { { Brem, BremP }, { Scad, ScadP },
    				{ Orr, OrrP }, { Jack, JackP }, { Mow, MowP }, { How, HowP },
    				{ McH, McHP }, { Mart, MartP },
    
    		};
    
    		table = new JTable(dataValues, columnNames);
    		table.setShowGrid(true);
    		table.setGridColor(Color.BLACK);
    
    		scrollPane = new JScrollPane(table);
    
    		panel.add(scrollPane, BorderLayout.WEST);
    		
    		frame = new JFrame("Statistics");
    		frame.setResizable(false);
    		frame.setLocation(840, 10);
    		frame.setSize(458, 174);
    		frame.add(panel);
    		frame.setVisible(true);
    		
    		refreshTable();
    	}
    	
    	public static void refreshTable(){
    		
    		System.out.println(BremP);
    		System.out.println("LOL");
    		table.updateUI();
    		table.validate();
    	}
    
    	
    
    }
    Thanks, and can anyone help me with my file IO because it sucks? I am trying to write the house points to a file and then access them and I feel there is a better way but I don't know how.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    this class is causing a null pointer exception
    Please copy and paste here the full text of the error message.

    How is this code being executed? I don't see the starting main method.
    Last edited by Norm; 05-30-2011 at 11:41 PM.

  3. #3
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at java.io.Writer.<init>(Writer.java:71)
    	at java.io.PrintWriter.<init>(PrintWriter.java:75)
    	at java.io.PrintWriter.<init>(PrintWriter.java:62)
    	at HouseHockey.ErrorMessages.<init>(ErrorMessages.java:34)
    	at HouseHockey.playerAttendance$8.actionPerformed(playerAttendance.java:271)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    	at java.awt.Component.processMouseEvent(Component.java:6374)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    	at java.awt.Component.processEvent(Component.java:6139)
    	at java.awt.Container.processEvent(Container.java:2085)
    	at java.awt.Component.dispatchEventImpl(Component.java:4736)
    	at java.awt.Container.dispatchEventImpl(Container.java:2143)
    	at java.awt.Component.dispatchEvent(Component.java:4566)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4621)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
    	at java.awt.Container.dispatchEventImpl(Container.java:2129)
    	at java.awt.Window.dispatchEventImpl(Window.java:2478)
    	at java.awt.Component.dispatchEvent(Component.java:4566)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:680)
    	at java.awt.EventQueue.access$000(EventQueue.java:86)
    	at java.awt.EventQueue$1.run(EventQueue.java:639)
    	at java.awt.EventQueue$1.run(EventQueue.java:637)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    	at java.awt.EventQueue$2.run(EventQueue.java:653)
    	at java.awt.EventQueue$2.run(EventQueue.java:651)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:650)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    I have the main method else where but if you need to see my other classes then ask.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    at HouseHockey.ErrorMessages.<init>(ErrorMessages.jav a:34)
    at HouseHockey.playerAttendance$8.actionPerformed(pla yerAttendance.java:271)
    These two lines refer to your code. At line 271 it creates a new ErrorMessages object
    What is the code in ErrorMessages at line 34? What variable at that line is null?

  5. #5
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    Java Code:
    package HouseHockey;
    
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    
    import javax.swing.BoxLayout;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JSplitPane;
    import javax.swing.JTable;
    import javax.swing.ListModel;
    import javax.swing.ListSelectionModel;
    import javax.swing.RowFilter;
    import javax.swing.table.TableRowSorter;
    
    public class playerAttendance {
    	
    	JFrame frame = new JFrame("Attendance");
    	JPanel panel = new JPanel();
    	JPanel panel2 = new JPanel();
    	JPanel panel3 = new JPanel();
    	JLabel space = new JLabel("");
    	  final static DefaultListModel listmodel = new DefaultListModel();
    	  final JList list = new JList(listmodel);
    	  JScrollPane pane2 = new JScrollPane(list);
    	  final static DefaultListModel listmodel2 = new DefaultListModel();
    	  final JList list2 = new JList(listmodel2);
    	  JScrollPane pane3 = new JScrollPane(list2);
    	  static Object data;
    	  Object data2;
    	  static Object[] ray;
    	
    	public playerAttendance(final String house1, final String house2){
    		
    		frame.add(panel);
    		
    		String Brem = "Bremner's";
    		String Scad = "Scadding's";
    		String Orr = "Orr's";
    		String Jack = "Jackson's";
    		String Mow = "Mowbray's";
    		String How = "Howard's";
    		String McH = "McHugh's";
    		String Mart = "Martland's";
    
    		String[] houses = { Brem, Scad, Orr, Jack, Mow, How, McH, Mart };
    		final JComboBox houselist = new JComboBox(houses);
    		String[] grades = { "Year 1", "Year 2", "Foundation Year", "IB1", "IB2" };
    		final JComboBox gradelist = new JComboBox(grades);
    		JButton go = new JButton("Filter Houses");
    		JButton go2 = new JButton("Filter Grades");
    		JButton go3 = new JButton("Filter Both");
    
    		JButton go4 = new JButton("Search");
    
    		JPanel navAtt = new JPanel();
    
    		navAtt.add(houselist);
    		navAtt.add(go);
    		navAtt.add(gradelist);
    		navAtt.add(go2);
    		navAtt.add(go3);
    		navAtt.add(go4);
    
    		panel.add(navAtt);
    
    		final JTable names = new JTable();
    
    
    		final DataFileModel model = new DataFileModel(
    				"/Users/eric.manget/Desktop/allstuds.xls");
    		names.setModel(model);
    		final TableRowSorter<DataFileModel> sorter = new TableRowSorter<DataFileModel>(
    				model);
    		final ArrayList<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>();
    		names.setRowSorter(sorter);
    		JScrollPane pane = new JScrollPane(names);
    		panel.add(pane);
    		JButton addPlayerhouse1 = new JButton("Add Player To " + house1);
    		JButton addPlayerhouse2 = new JButton("Add Player To " + house2);
    		JButton remove1 = new JButton("Remove Player");
    		JButton remove2 = new JButton("Remove Player");
    		
    		panel.add(panel2);
    		
    		final JFrame frame2 = new JFrame("Navigator");
    		JPanel panelN = new JPanel();
    		frame2.add(panelN);
    		frame2.setSize(350,60);
    		frame2.setResizable(false);
    		frame2.setLocation(890,0);
    		JButton close = new JButton("Close");
    		JButton complete = new JButton("Continue");
    		JButton mainB = new JButton("Main Page");
    		
    		panelN.add(complete);
    		panelN.add(mainB);
    		panelN.add(close);
    		frame2.setVisible(true);
    		
    		JLabel playinghouse1 = new JLabel("                           " + house1);
    		panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
    		panel2.add(playinghouse1);
    		panel2.add(pane2);
    		panel2.add(addPlayerhouse1);
    		panel2.add(remove1);
    		
    
    		JLabel playinghouse2 = new JLabel("                           " + house2);
    		panel2.add(playinghouse2);
    		panel2.add(pane3);
    		panel2.add(addPlayerhouse2);
    		panel2.add(remove2);
    		
    		frame.setResizable(false);
    		frame.setSize(810, 495);
    		frame.setVisible(true);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		names.getTableHeader().setResizingAllowed(false);
    		names.getTableHeader().setReorderingAllowed(false);
    		
    		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION );
    		
    		
    		
    
    		go.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				String text = houselist.getSelectedItem().toString();
    
    				if (text.length() == 0) {
    					sorter.setRowFilter(null);
    				} else {
    					sorter.setRowFilter(null);
    					sorter.setRowFilter(RowFilter.regexFilter(text));
    
    				}
    			}
    		});
    		go2.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				String text2 = gradelist.getSelectedItem().toString();
    
    				if (text2.length() == 0) {
    					sorter.setRowFilter(null);
    				} else {
    					sorter.setRowFilter(null);
    					sorter.setRowFilter(RowFilter.regexFilter(text2));
    
    				}
    
    			}
    
    		});
    		go3.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				String list1 = houselist.getSelectedItem().toString();
    				String list2 = gradelist.getSelectedItem().toString();
    
    				RowFilter<Object, Object> text = RowFilter.regexFilter(list1);
    				RowFilter<Object, Object> text2 = RowFilter.regexFilter(list2);
    
    				filters.clear();
    				filters.add(text);
    				filters.add(text2);
    
    				sorter.setRowFilter(null);
    				sorter.setRowFilter(RowFilter.andFilter(filters));
    				
    			}
    
    		});
    		go4.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				SEARCH search = new SEARCH(filters,sorter,model);
    				
    			}
    
    		});
    		
    		
    		addPlayerhouse1.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				Object houseconf1 = names.getValueAt(names.getSelectedRow(), 3);
    				
    				if(!houseconf1.equals(house1)){
    					
    					ErrorMessages confmsg1 = new ErrorMessages(frame);
    					confmsg1.addingplayer();
    					
    				}
    				else{
    				
    				Object listelement1 = names.getValueAt(names.getSelectedRow(), 2);
    				Object listelement2 = names.getValueAt(names.getSelectedRow(), 1);
    				listmodel.addElement(listelement1 + " " + listelement2);
    				
    				
    				
    				for(int i = 0; i < listmodel.getSize(); i++) {
    				     
    				int n = listmodel.getSize();
    				
    					
    						 
    
    					 
    					
    				}
    					}
    				}
    			});
    		
    		
    		addPlayerhouse2.addActionListener(new ActionListener() {
    				public void actionPerformed(ActionEvent actionEvent) {
    					
    					Object houseconf2 = names.getValueAt(names.getSelectedRow(), 3);
    					
    					if(!houseconf2.equals(house2)){
    						
    						ErrorMessages confmsg2 = new ErrorMessages(frame);
    						confmsg2.addingplayer();
    						
    					}
    					else{
    					
    					Object listelement3 = names.getValueAt(names.getSelectedRow(), 2);
    					Object listelement4 = names.getValueAt(names.getSelectedRow(), 1);
    					listmodel2.addElement(listelement3 + " " + listelement4);
    					
    					}
    			}
    
    		});
    		
    		close.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				ErrorMessages rusure = new ErrorMessages(frame);
    				
    				rusure.unsavedData();
    				
    			}
    
    		});
    		
    		complete.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    				
    				int size = list.getModel().getSize();
    				int size2 = list2.getModel().getSize();
    				
    				if(size < 6){
    	
    					ErrorMessages rusure3 = new ErrorMessages(frame);
    					rusure3.notEnoughPlayers(house1,house2);
    					
    				}
    				
    				if(size2 < 6){
    					
    					ErrorMessages rusure4 = new ErrorMessages(frame);
    					rusure4.notEnoughPlayers(house2,house1);
    			
    				}
    				
    				else{
    				
    				frame.dispose();
    				frame2.dispose();
    				
    				new GameScoreSheet();
    				
    				}
    				
    			}
    
    		});
    		
    		mainB.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				ErrorMessages rusure2 = new ErrorMessages(frame);
    				
    				rusure2.navMain();
    				
    			}
    
    		});
    		
    		remove1.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				
    				listmodel.removeElement(list.getSelectedValue());
    				
    			}
    
    		});
    		
    		remove2.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				listmodel2.removeElement(list2.getSelectedValue());
    				
    			}
    
    		});
    		
    	}
    	
    	public static void getL1(JList list){
    		
    		list.setModel(listmodel);
    		
    	}
    	public static void getL2(JList list){
    		
    		list.setModel(listmodel2);
    		
    	}
    		
    }

  6. #6
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    AHHH im so confused I have been struggling for so long now.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Did you look at the line in your code to see what variable was null?

  8. #8
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    ya its the printwriter but what can I do about it?

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    What variable is null?
    Assign a value to the null variable so that it is not null.

    Declaring variables does NOT give them values (except for primitives like int or boolean)

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

    Default

    Post the offending line here.

  11. #11
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    Fubarable - ?

    Norm - Ok sure. Thanks, anything else needs fixing?

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    anything else needs fixing?
    There is way too much code for anyone to look thru.

    Did you find and fix the null variable problem?

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

    Default

    Quote Originally Posted by loopsnhoops View Post
    Fubarable - ?
    If you've solved your problem already, you may disregard this, but if not, you and only you have the full code, and you have the error message the should indicate which line in that code is causing the nullpointerexception. Again, please post that line of offending code here.

  14. #14
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    I did something and now it is letting me venture farther in my program without errors but I am getting another error message.

    Here are the things I did.

    Java Code:
    	File file = new File("/Users/eric.manget/Desktop/Scores.txt");
    
    	int martlands = 0;
    	int scaddings = 0;
    	int mchughs = 0;
    	int mowbray = 0;
    	int orrs = 0;
    	int brem = 0;
    	int jacksons = 0;
    	int howards = 0;
       
    	PrintWriter out;
    
    	
    	public ErrorMessages(final JFrame frame2){
    
    		panel.add(label);
    		frame.add(panel);
    		frame.setSize(300,65);
    		frame.setVisible(true);
    		frame.setResizable(false);
    	
    		 FileWriter outFile = null;
    		try {
    			outFile = new FileWriter(file);
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    			PrintWriter out = new PrintWriter(outFile);
    		close.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    				
    				frame.dispose();
    				
    			}
    		});

    Here is my error.

    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at HouseHockey.ErrorMessages$6.actionPerformed(ErrorMessages.java:182)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    	at java.awt.Component.processMouseEvent(Component.java:6374)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    	at java.awt.Component.processEvent(Component.java:6139)
    	at java.awt.Container.processEvent(Container.java:2085)
    	at java.awt.Component.dispatchEventImpl(Component.java:4736)
    	at java.awt.Container.dispatchEventImpl(Container.java:2143)
    	at java.awt.Component.dispatchEvent(Component.java:4566)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4621)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
    	at java.awt.Container.dispatchEventImpl(Container.java:2129)
    	at java.awt.Window.dispatchEventImpl(Window.java:2478)
    	at java.awt.Component.dispatchEvent(Component.java:4566)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:680)
    	at java.awt.EventQueue.access$000(EventQueue.java:86)
    	at java.awt.EventQueue$1.run(EventQueue.java:639)
    	at java.awt.EventQueue$1.run(EventQueue.java:637)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    	at java.awt.EventQueue$2.run(EventQueue.java:653)
    	at java.awt.EventQueue$2.run(EventQueue.java:651)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:650)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

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

    Default

    Again you're not indicating to us which lines of code are causing the error message.
    Last edited by Fubarable; 05-31-2011 at 01:05 AM.

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    at HouseHockey.ErrorMessages$6.actionPerformed(ErrorM essages.java:182)
    You need to be able to read thru the error message and find your problem.
    Start from the bottom and scan up until you find a reference to one of your classes. Here the error occured at line 182 in ErrorMessages.java. Again its a NPE. Look at line 182 and figure out which variable is null. If you can't determine which one, add a System.out.println("var1=" + var1 + ", var2=" + var2 .. (replacing var1 etc with variables from the line with the NPE) to your code just before line 182. Execute the program again and look at what is printed out. One of the variables should have a null value. Now back up in the code to see why.

  17. #17
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    Thank you Norm for that tip on errors. It seems that when I try to write to the file the program starts to whine. Can you give suggestions on how to link the integer I am writing with the hockey house.

  18. #18
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    P.S: What does NPE stand for?

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

    Default

    Quote Originally Posted by loopsnhoops View Post
    P.S: What does NPE stand for?
    That's shorthand for NullPointerException -- what your code is throwing.

    There are line numbers in the error messages together with Java file name, simply find the line that corresponds with that line number.

  20. #20
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    ya see it occurs when i try to write which is 32 lines and the error occurs when certain conditions are met. So I have to solve the main problem which is the inability to write. But sadly I am not diversified in this language.

Page 1 of 2 12 LastLast

Similar Threads

  1. look @ code and give ideas! Install new code....
    By turbowhat in forum New To Java
    Replies: 2
    Last Post: 04-27-2011, 03:08 AM
  2. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  3. Replies: 1
    Last Post: 03-04-2010, 11:19 AM
  4. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 11:14 AM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

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