Results 1 to 6 of 6
  1. #1
    Dozo23 is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Roman Numeral Code

    I need to write a program that produces a gui with File, Edit and Display menu. In the File menu you have the options of open, to open a file containing roman numerals and exit, to stop the program. In edit you have the option of add, which allows the user to add their own roman numeral to the list. then in display you have the option of displaying the sorted and inorder roman numerals. the program displays the gui and pretty much everything works but when i open a text file i get Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException follow by other exceptions in the console.

    here is my code. i have twelve classes.

    Java Code:
    /********************************************************************************************
     *    This Program Reads in a file, creates two lists, appends, inserts, and finally creates a GUI.
     *  
     *
     */
    import java.awt.*;
    import javax.swing.*;
    public class Project3{
    
    	public static void main(String[] args){
    		
    		
    		//  If there is no command line argument for the file name a message will be
    		//  displayed and the program terminated.
    		//
    
    		//  The file is opened and each line is read, converted to a Roman Numeral and
    		//  put them into two different Roman Numeral Linked List one is sorted and the other is in order  
    		//	
    		
    		//
    		//   Instantiate the GUI, passing the two lists.
    		//
    		new RomanNumeralGUI("Roman Numeral - Project 3");
    
    	}
    }
    Java Code:
    /***************************************************************************
     * 
     *    A class that implements the use of Roman Numeral Node
     *  
     * 
     */
    
    public class RomanNumeralNode {
    
    	RomanNumeral data;
    	RomanNumeralNode next;
    	/*************************************************************************
    	 * Creates an object called RomanNumeralNode with a String and a pointer   
    	 * @param data The String part of the object 
    	 * @param next The pointer part of the object 
    	 */
    	public RomanNumeralNode(RomanNumeral data,RomanNumeralNode next){
    		this.data=data;
    		this.next=next;
    	}
    	/**************************************************************************
    	 * Creates an object called RomanNumeralNode with empty parameter
    	 */
    	public RomanNumeralNode(){
    		this.data=null;
    		this.next=null;
    	}
    	/***************************************************************************
    	 * Creates an object called RomanNumeralNode with a String and null pointer
    	 * @param data The String part of the object 
    	 */
    	public RomanNumeralNode(RomanNumeral data){
    		this.data=data;
    		this.next=null;
    	}
    }
    Java Code:
    public class InOrderRomanNumeralList extends RomanNumeralList{
    	/** First node in Roman Numeral linked list - dummy node */
    	private RomanNumeralNode first;
    	/** Last node in Roman Numeral linked list */
    	private RomanNumeralNode last;
    	/** Number of data items in the list. */
    	private int length=0;
    	
    	public void add(RomanNumeral rn){
    		RomanNumeralNode n = new RomanNumeralNode(rn);
    		last.next=n;
    		last=n;
    		length ++;
    	}
    
    	
    }
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class EditMenuHandler implements ActionListener {
       JFrame jframe;
       public EditMenuHandler (JFrame jf) {
          jframe = jf;
       }
       public void actionPerformed(ActionEvent event) {
          String menuName = event.getActionCommand();
          String inputNumeral;
          if (menuName.equals("Add")){
        	  inputNumeral = JOptionPane.showInputDialog(null, "Please enter a Roman Numeral");
        	  if(inputNumeral.length() == 0){
    				inputNumeral = JOptionPane.showInputDialog(null, "That is not a valid Roman Numeral. Please try again");
    			}
        	  
        	  for(int i = 0; i < inputNumeral.length(); i++){
      			//Roman Numeral (M,D,C,L,V,I)  
        		if(inputNumeral.length() == 0){
      				inputNumeral = JOptionPane.showInputDialog(null, "That is not a valid Roman Numeral. Please try again");
        		}
      			if(inputNumeral.charAt(i)=='M'||inputNumeral.charAt(i)=='D'||inputNumeral.charAt(i)=='C'||inputNumeral.charAt(i)=='L'||inputNumeral.charAt(i)=='X'||inputNumeral.charAt(i)=='V'||inputNumeral.charAt(i)=='I'){
      				FileMenuHandler.getInOrderList().add(new RomanNumeral(inputNumeral));
      				FileMenuHandler.getSortedList().add(new RomanNumeral(inputNumeral));	
      			}
      			else if(inputNumeral.charAt(i)!='M'||inputNumeral.charAt(i)!='D'||inputNumeral.charAt(i)!='C'||inputNumeral.charAt(i)!='L'||inputNumeral.charAt(i)!='X'||inputNumeral.charAt(i)!='V'||inputNumeral.charAt(i)!='I'){
      				inputNumeral = JOptionPane.showInputDialog(null, "That is not a valid Roman Numeral. Please try again");
      			}
      			
      				
        	  }
          }
       }
    }
    Java Code:
    // TextFileInput.java
    // Copyright (c) 2000, 2005 Dorothy L. Nixon.  All rights reserved.
    
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.io.IOException;
    
    /**
     * Simplified buffered character input
     * stream from an input text file.
     * Manages an input text file,
     * handling all IOExceptions by generating
     * RuntimeExcpetions (run-time error
     * messages).
     *
     * If the text file cannot be created,
     * a RuntimeException is thrown,
     * which by default results an an
     * error message being printed to
     * the standard error stream.
     *
     * @author D. Nixon
     */
    public class TextFileInput  {
    
       /**  Name of text file  */
       private String filename;
    
       /**  Buffered character stream from file  */
       private BufferedReader br;  
    
       /**  Count of lines read so far.  */
       private int lineCount = 0;
    
       /**
        * Creates a buffered character input
        * strea, for the specified text file.
        *
        * @param filename the input text file.
        * @exception RuntimeException if an
        *          IOException is thrown when
        *          attempting to open the file.
        */
       public TextFileInput(String filename)
       {
          this.filename = filename;
          try  {
             br = new BufferedReader(
                      new InputStreamReader(
                          new FileInputStream(filename)));
          } catch ( IOException ioe )  {
             throw new RuntimeException(ioe);
          }  // catch
       }  // constructor
    
       /**
        * Closes this character input stream.
        * No more characters can be read from
        * this TextFileInput once it is closed.
        * @exception NullPointerException if
        *        the file is already closed.
        * @exception RuntimeException if an
        *       IOException is thrown when
        *       closing the file.
        */
       public void close()
       {
          try  {
             br.close();
             br = null;
          } catch ( NullPointerException npe )  {
             throw new NullPointerException(
                            filename + "already closed.");
          } catch ( IOException ioe )  {
             throw new RuntimeException(ioe);
          }  // catch
       }  // method close
    
       /**
        * Reads a line of text from the file and
        * positions cursor at 0 for the next line.
        * Reads from the current cursor position
        * to end of line.
        * Implementation does not invoke read.
        *
        * @return the line of text, with
        *         end-of-line marker deleted.
        * @exception RuntimeException if an
        *          IOException is thrown when
        *          attempting to read from the file.
        */
       public String readLine()
       {
          return readLineOriginal();
       }  // method readLine()
    
       /**
        * Returns a count of lines
        * read from the file so far.
        */
       public int getLineCount()  { return lineCount; }
    
       /**
        * Tests whether the specified character is equal,
        * ignoring case, to one of the specified options.
        *
        * @param toBeChecked the character to be tested.
        * @param options a set of characters
        * @return true if <code>toBeChecked</code> is
        *         equal, ignoring case, to one of the
        *         <code>options</code>, false otherwise.
        */
       public static boolean isOneOf(char toBeChecked,
                                     char[] options)
       {
          boolean oneOf = false;
          for ( int i = 0; i < options.length && !oneOf; i++ )
             if ( Character.toUpperCase(toBeChecked)
                       == Character.toUpperCase(options[i]) )
                oneOf = true;
          return oneOf;
       }  // method isOneOf(char, char[])
    
       /**
        * Tests whether the specified string is one of the
        * specified options.  Checks whether the string
        * contains the same sequence of characters (ignoring
        * case) as one of the specified options.
        *
        * @param toBeChecked the String to be tested
        * @param options a set of Strings
        * @return true if <code>toBeChecked</code>
        *         contains the same sequence of
        *         characters, ignoring case, as one of the
        *         <code>options</code>, false otherwise.
        */
       public static boolean isOneOf(String toBeChecked,
                                     String[] options)
       {
          boolean oneOf = false;
          for ( int i = 0; i < options.length && !oneOf; i++ )
             if ( toBeChecked.equalsIgnoreCase(options[i]) )
                oneOf = true;
          return oneOf;
       }  // method isOneOf(String, String[])
     
       /**
        * Reads a line from the text file and ensures that
        * it matches one of a specified set of options.
        *
        * @param options array of permitted replies
        *
        * @return the line of text, if it contains the same
        *         sequence of characters (ignoring case for
        *         letters) as one of the specified options,
        *         null otherwise.
        * @exception RuntimeException if the line of text
        *         does not match any of the specified options,
        *         or if an IOException is thrown when reading
        *         from the file.
        * @exception NullPointerException if no options are
        *         provided, or if the end of the file has been
        *         reached.
        */
       public String readSelection(String[] options)
       {
          if ( options == null || options.length == 0 )
             throw new NullPointerException(
                                "No options provided for "
                                + " selection to be read in file "
                                + filename + ", line " 
                                + (lineCount + 1) + ".");
    
          String answer = readLine();
    
          if ( answer == null )
             throw new NullPointerException(
                                "End of file "
                                + filename + "has been reached.");
    
          if ( !TextFileInput.isOneOf(answer, options) )  {
             String optionString = options[0];
             for ( int i = 1; i < options.length; i++ )
                optionString += ", " + options[i];
             throw new RuntimeException("File " + filename
                                + ", line " + lineCount
                                + ": \"" + answer
                                + "\" not one of "
                                + optionString + ".");
          }  // if
          return answer;
      }  // method readSelection
    
       /**
        * Reads a line from the text file and ensures that
        * it matches, ignoring case, one of "Y", "N", "yes",
        * "no", "1", "0", "T", "F", "true", or "false".
        * There must be no additional characters on the line.
        *
        * @return <code>true</code> if the line matches
        *        "Y", "yes", "1" "T", or "true".
        *        <code>false</code> if the line matches
        *        "N", "no", "0", "F", or "false".
        * @exception RuntimeException if the line of text
        *        does not match one of "Y", "N", "yes",
        *        "no", "1", "0", "T", "F", "true", or "false",
        *        or if an IOException is thrown when reading
        *        from the file.
        * @exception NullPointerException if the end of the
        *        file has been reached.
        */
       public boolean readBooleanSelection()
       {
          String[] options = {"Y", "N", "yes", "no", "1", "0",
                              "T", "F", "true", "false"};
          String answer = readSelection(options);
          return isOneOf(answer,
                         new String[] {"Y", "yes", "1", "T", "true"} );
       }  // method askUserYesNo
    
       /**
        * Reads a line of text from the file and
        * increments line count.  (This method
        * is called by public readLine and is
        * final to facilitate avoidance of side
        * effects when public readLine is overridden.)
        *
        * @return the line of text, with
        *         end-of-line marker deleted.
        * @exception RuntimeException if an
        *          IOException is thrown when
        *          attempting to read from the file.
        */
       protected final String readLineOriginal()
       {
           try  {
              if ( br == null )
                 throw new RuntimeException(
                                    "Cannot read from closed file "
                                    + filename + ".");
              String line = br.readLine();
              if ( line != null )
                 lineCount++;
              return line;
           } catch (IOException ioe)  {
              throw new RuntimeException(ioe);
           }  // catch
       }  // method readLineOriginal
    }  // class TextFileInput
    Java Code:
    public class SortedRomanNumeralList extends RomanNumeralList{
    	/** First node in Roman Numeral linked list - dummy node */
    	private RomanNumeralNode first;
    	/** Last node in Roman Numeral linked list */
    	private RomanNumeralNode last;
    	/** Number of data items in the list. */
    	private int length=0;
    	
    	public void add(RomanNumeral rn){
    
    		RomanNumeralNode n = new RomanNumeralNode(rn);
    		RomanNumeralNode temp = first.next;
    		//Roman Numeral to be inserted right after the last node of the list
    		if(temp==null|| rn.compareTo(last.data)>0) {
    			last.next=n;
    			last=n;
    			length++;
    		}
    		//Roman Numeral to be inserted right before the first node of the list (after the dummy node)
    		else if(rn.compareTo(temp.data)<0){
    			n.next=temp;
    			first.next=n;
    
    		}
    		else{
    			//Roman numeral to be inserted in the middle of the list
    			while(temp.next!=null && (rn.compareTo(temp.next.data))>0) {
    				temp=temp.next;
    			}
    			n.next=temp.next;
    			temp.next=n;
    		}
    	}
    
    }
    Java Code:
    /***************************************************************************
     * 
     *    A class that implements the use of Roman Numerals in a linked list 
     
     * 
     */
    
    public abstract class RomanNumeralList {
    	/** First node in Roman Numeral linked list - dummy node */
    	private RomanNumeralNode first;
    	/** Last node in Roman Numeral linked list */
    	private RomanNumeralNode last;
    	/** Number of data items in the list. */
    	private int length=0;
    
    	/*************************************************************
    	 * Creates  RomanNumeralList object using RomanNumeral Node
    	 *  
    	 */
    	public RomanNumeralList(){
    		RomanNumeralNode rn = new RomanNumeralNode();
    		first = rn;
    		last = rn;
    		length =0;
    	}//constructor
    
    	
    	public abstract void add(RomanNumeral rn);
    	/**********************************************************************************
    	 * Gives the number of data values currently stored in this RomanNumeralList.
    	 * 
    	 * @return the length of the RomanNumeralList 
    	 */
    	public int length(){
    		return length;
    	}//length method
    
    	/***********************************************************************************************
    	 * Determine whether two Roman numerals are equal 
    	 * 
    	 */
    	public boolean equals(Object other){
    		if(other==null || getClass()!=other.getClass() || length!=((RomanNumeralList)other).length)
    			return false;
    		RomanNumeralNode p=first.next;
    		RomanNumeralNode q=((RomanNumeralList)other).first.next;
    		for(int i=0;i<length;i++){
    			if(p.data!=q.data)  return false;
    			p=p.next;
    			q=q.next;
    		}
    		return true;
    	}//equals method
    
    	/************************************************************************************
    	 * Construct and return a String containing the data of each node separated with a new line
    	 * 
    	 * @return String representation of elements in linked list delimited by a
    	 *         new line
    	 */
    
    	public String toString() {
    		RomanNumeralNode p = first.next;
    		String returnRNString = "";
    		while (p != null) {
    			returnRNString += p.data + "\n";
    			p = p.next;
    		}
    		return returnRNString;
    	}//toString method
    
    	/*************************************************************************************
    	 * Creates a new RNLinkedlistIterator object 
    	 * 
    	 * @return RNLinkedListIterator object
    	 */
    	public RNLinkedListIterator reset() {
    		return new RNLinkedListIterator(first.next);
    	} //RNLinkedListIterator method
    
    
    
    }
    Java Code:
    public class RomanNumeral {
    	private String RomanString;
    	/**
    	 * The RomanNumeral Sets up a String as Roman Numeral
    	 * @param rn String to be set as Roman Numeral
    	 */
    	public RomanNumeral (String rn){
    		if(!isValid(rn))
    			throw new IllegalArgumentException("Invalid Roman numeral");
    		else  
    			RomanString=rn;
    	}//RomanNumeral constructor 
    
    	/**
    	 * Evaluates the Roman Numeral into Decimal 
    	 * @return Roman Numeral in decimal value
    	 */
    	public int getDecimalValue(){
    		int r=0;
    		r+=getInt(RomanString.charAt(RomanString.length()-1));
    		//Parse through the Roman Numeral String and calculate decimal value
    		for(int i=RomanString.length()-2;i>=0;i--){
    			if( getInt(RomanString.charAt(i))>=getInt(RomanString.charAt(i+1))){
    				r+=getInt(RomanString.charAt(i));	
    			}//if
    			else r-=getInt(RomanString.charAt(i));
    		}//for
    		return r;
    	}//getDecimalValue method
    	
    	/**
    	 * Compares tow Roman numerals
    	 * @param rn The Roman numeral that we are comparing
    	 * @return positive integer if comparing value on the left is bigger,negative integer if
    	 *  comparing value on the left is smaller and zero  when both are same 
    	 */
    	public int compareTo(RomanNumeral rn){
    		return(getDecimalValue()-rn.getDecimalValue());
    	}//compareTo method
    	
    	/**
    	 * Test class equivalence
    	 * @param rn The Roman numeral object that we are comparing
    	 * @return returns true only if the Roman Numeral object is equal to the the object with which it is being compared 
    	 */
    	public boolean equals(Object rn){
    		return(rn!=null && getClass()==rn.getClass()&& RomanString.equals(((RomanNumeral)rn).RomanString));
    	}//equals method
    	
    	/**
    	 * @return Return a String Roman Numeral
    	 */
    	public String toString(){
    		return RomanString;
    	}//toString method
    
    	/**
    	 *Takes a Character of Roman Numeral and returns its value
    	 * @param r  the character to be evaluated
    	 * @return the integer value of a Roman Numeral
    	 */
    	private static int getInt(char r){
    		if(r=='I') return 1; //I represents 1 in Roman
    		else if(r=='V') return 5; //V represents 5 in Roman
    		else if(r=='X') return 10;//X represents 10 in Roman
    		else if(r=='L') return 50;//L represents 50 in Roman
    		else if(r=='C') return 100;//C represents 100 in Roman
    		else if (r=='D') return 500;//D represents 500 in Roman
    		else return 1000;//M represents 1000
    
    	}//getInt method
    	
    	/**
    	 * Evaluates whether a String contains all valid Roman Numeral character
    	 * @param userInput The String to be evaluated
    	 * @return the method returns true if passed parameter is a valid Roman Numeral
    	 */
    	private boolean isValid(String userInput){
    		//checks each character of String userInput whether it has any error  
    		for(int i = 0; i < userInput.length(); i++){
    			//Roman Numeral (M,D,C,L,V,I)
    			if(userInput.charAt(i)=='M'||userInput.charAt(i)=='D'||userInput.charAt(i)=='C'||userInput.charAt(i)=='L'
    					||userInput.charAt(i)=='X'||userInput.charAt(i)=='V'||userInput.charAt(i)=='I'){
    				return true;
    			}
    		}
    		return false;
    	}//isValid method
    }
    Java Code:
    /***************************************************************************
     * 
     *    A class that extends Jframe to print RomanNumeral LinkedList into a GUI
     *   
     * 
     */
    
    
    import javax.swing.*;
    import java.awt.*;
    
    public class RomanNumeralGUI extends JFrame{
    	/************************************************************************
    	 * A GUI for displaying two lists of RomanNumerals, one unsorted, one sorted. 
    	 * 
    	 * @param title The String to be set as the title of the GUI
    	 * @param left  The Unsorted List
    	 * @param right The Sorted List
    	 */
    	
    	JMenuBar menuBar = new JMenuBar();
    	static TextArea left =new TextArea();
    	public RomanNumeralGUI(String title) {
    	   	   
    		setTitle(title);
    		setSize(400,400);
    		
    		createFileMenu();
    		createEditMenu();
    		createDisplayMenu();
    		setJMenuBar(menuBar);
    		//setLayout(new GridLayout(1,2));
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		//
    		//  Put the TextAreas which will contain the RomanNumerals in the GUI
    		//
    		getContentPane().add(left);
    		//
    		// Go through the unsorted list and put each RomanNumeral in the left
    		// TextArea
          //
    		
    		
    		
    	
    
    		setVisible(true);
    	}
    	public static TextArea getTextArea() {
    		return left;
    	}
    	
    	private void createFileMenu(){
    		JMenuItem item;
    		JMenu fileMenu = new JMenu("File");
    		FileMenuHandler fmh = new FileMenuHandler(this);
    		
    		item = new JMenuItem("Open");
    		item.addActionListener( fmh );
    		fileMenu.add( item );
    		
    		fileMenu.addSeparator();
    		
    		item = new JMenuItem("Exit");
    		item.addActionListener( fmh );
    		fileMenu.add(item);
    		
    		
    		menuBar.add(fileMenu);
    	}
    	private void createEditMenu(){
    		JMenuItem item2;
    		JMenu editMenu = new JMenu("Edit");
    		EditMenuHandler fmh = new EditMenuHandler(this);
    		
    		item2 = new JMenuItem("Add");
    		item2.addActionListener( fmh );
    		editMenu.add( item2 );
    		
    
    		menuBar.add(editMenu);
    	}
    	private void createDisplayMenu(){
    		JMenuItem item3;
    		JMenu displayMenu = new JMenu("Display");
    		DisplayMenuHandler fmh = new DisplayMenuHandler(this);
    		
    		item3 = new JMenuItem("Unsorted");
    		item3.addActionListener( fmh );
    		displayMenu.add(item3);
    		
    		displayMenu.addSeparator();
    		
    		item3 = new JMenuItem("Sorted");
    		item3.addActionListener( fmh );
    		displayMenu.add(item3);
    		
    
    		menuBar.add( displayMenu );
    	}
    }
    Java Code:
    /***************************************************************************
     * 
     *    A class that implements the use of RomanNumeral LinkedList Iterator
     *  
     * 
     */
    
    public class RNLinkedListIterator {
    	private RomanNumeralNode node;
    	/***************************************************************
    	 * Creates an object RNLinkedListIterator with Roman Numeral Node 
    	 * 
    	 * @param first The Roman Numeral Node
    	 */
    	public RNLinkedListIterator(RomanNumeralNode first) {
    		node =first;
    	}
    
    	/****************************************************************
    	 * Determines whether the list has next Node
    	 * 
    	 * @return boolean
    	 */
    	public boolean hasNext(){
    		return (node !=null);
    	}
    
    	/*****************************************************************
    	 * Returns the next available Roman Numeral 
    	 * 
    	 * @return next Roman Numeral 
    	 */
    
    	public RomanNumeral next(){
    		if(node==null)
    			throw new NullPointerException("Roman Numeral List empty");
    		RomanNumeral currentdata = node.data;
    		node=node.next;
    		return currentdata;
    	} 
    
    
    }
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class FileMenuHandler implements ActionListener {
       JFrame jframe;
       static RomanNumeralList inOrder,sorted;
       public FileMenuHandler (JFrame jf) {
       jframe = jf;
       }
       public void actionPerformed(ActionEvent event) {
          String menuName = event.getActionCommand();
          if (menuName.equals("Open")){
      		String inputLine;
      		inOrder = new InOrderRomanNumeralList();
      		sorted = new SortedRomanNumeralList();
      		JFileChooser fd = new JFileChooser();
      		fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
      		fd.showOpenDialog(null);
        	TextFileInput in = new TextFileInput(fd.getSelectedFile().getPath());
      		inputLine = in.readLine();
      		
      		while (inputLine != null){
      			try {
      				RomanNumeral rn = new RomanNumeral(inputLine);
      				inOrder.add(rn);
      				sorted.add(rn);
      			}
      			catch (IllegalArgumentException iae) {
      				System.out.println("Illegal Roman numeral: "+inputLine);
    
      			}
      			finally {
      				inputLine = in.readLine();
      			}
      		}
          }
          else if (menuName.equals("Exit")){
        	  System.exit(0);
          }
       }
       public static RomanNumeralList getInOrderList() {
    	   return inOrder;
       }
       public static RomanNumeralList getSortedList() {
    	   return sorted;
       }
    }
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class DisplayMenuHandler implements ActionListener {
       JFrame jframe;
       public DisplayMenuHandler (JFrame jf) {
          jframe = jf;
       }
       public void actionPerformed(ActionEvent event) {
          String menuName = event.getActionCommand();
          if (menuName.equals("Unsorted")){
        	  RomanNumeralList inOrder = FileMenuHandler.getInOrderList();
        	  	RNLinkedListIterator rnIterator = inOrder.reset();
        	  	TextArea myTextArea = RomanNumeralGUI.getTextArea();
        	  	myTextArea.setText("");
        	  	while( rnIterator.hasNext()){
        	  		myTextArea.append(rnIterator.next() + "\n");
        	  	}
        		  
        	  
          }
          else if (menuName.equals("Sorted")){
        	  RomanNumeralList sorted = FileMenuHandler.getSortedList();
      	  	RNLinkedListIterator rnIterator = sorted.reset();
      	  	TextArea myTextArea = RomanNumeralGUI.getTextArea();
      	  	myTextArea.setText("");
      
      	  	while( rnIterator.hasNext()){
      	  		myTextArea.append(rnIterator.next() + "\n");
            }
          }
       }
    }

  2. #2
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    3

    Default Re: Roman Numeral Code

    which line is this null pointer exception on? and which Class? :)

  3. #3
    Dozo23 is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Roman Numeral Code

    line 34 in DisplayMenuHandler class.

    here is exactly what is displayed in the console:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at DisplayMenuHandler.actionPerformed(DisplayMenuHand ler.java:34)
    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.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unk nown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mou seReleased(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)

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,178
    Rep Power
    20

    Default Re: Roman Numeral Code

    our code above for DisplayMenuHandler does not have a line 34.
    We can't do much unless you show us exactly where the error is coming from.
    All we can say is "something on line 34 is null and you are attempting to call a method/access an attribute of it".
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,729
    Blog Entries
    7
    Rep Power
    21

    Default Re: Roman Numeral Code

    Quote Originally Posted by Dozo23 View Post
    Java Code:
    		//
    		//   Instantiate the GUI, passing the two lists.
    		//
    		new RomanNumeralGUI("Roman Numeral - Project 3");
    I love those incorrect comments; or is it the code itself?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Dozo23 is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Roman Numeral Code

    I was able to solve the problem. it turned out that the linked list needed some work. so after playing around with it for a while, i was able to get the program to work.

Similar Threads

  1. String to Int: Roman Numeral Class
    By tylerkung in forum New To Java
    Replies: 5
    Last Post: 09-22-2011, 05:31 AM
  2. Convert year to roman numeral.
    By jdm113497 in forum New To Java
    Replies: 2
    Last Post: 03-31-2011, 10:15 PM
  3. convert roman numeral to number
    By the beginner in forum New To Java
    Replies: 3
    Last Post: 01-27-2011, 07:49 AM
  4. How to identify a roman numeral
    By dunworry in forum New To Java
    Replies: 13
    Last Post: 12-19-2010, 09:13 AM
  5. Roman numeral to Decimal
    By hector100 in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2009, 08:48 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
  •