Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Error: Null Exception on Array of classes

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Error: Null Exception on Array of classes

    Error:
    java.lang.NullPointerException
    	at AxisManager.CreateAxes(AxisManager.java:15)

    Axis Manager:
    public class AxisManager {
    	//store axises in array
    	//store axes order (left to right)
    	private Axis[] m_axes;
    	private int[] m_axesOrder;
     
    	public void CreateAxes(int numAxesIN){
    		m_axes = new Axis[numAxesIN];
    		m_axesOrder = new int[numAxesIN];
    		for(int i = 0; i < m_axes.length; i++){
    			System.out.println("i:"+ i); 
    			m_axesOrder[i] = i;
    			m_axes[i].SetID(i);      //<-Line 15: Error!
    		}
    	}
    }

    Axis:
    public class Axis {
    	private int m_maxScale = 0;
    	private int m_minScale = 0;
    	private int m_unit = 0; //unit measures on the scale
    	private String m_label = "";
    	private Colour m_colour = new Colour();
     
    	private String m_name ="";
    	private int m_id = 0;
     
    	private Coordinate[] m_position = new Coordinate[1]; //array 0 = top, 1=bottom
     
    	public void SetLabel(String labelIN){
    		m_label = labelIN;
    	}
     
    	public void SetMinAndMax(int minIN,int maxIN){
    		m_minScale = minIN;
    		m_maxScale = maxIN;	
    	}
     
    	public String GetLabel(){
    		return m_label;
    	}
     
    	public void SetID(int idIN){
    		m_id = idIN;
    	}
     
    }

    XML Reader to grab the data and create the Axis Manager:
     
    public class XMLReader {
     
       private PolyManager thePolyManager = new PolyManager();
       private AxisManager theAxisManager = new AxisManager();
     
       public XMLRead(String filenameIN){
          ...
          theAxisManager = new AxisManager();
          theAxisManager.CreateAxes(5);
          ...
       }				
     
    }

    The main program:
    public class TestingProcessing {
     
    	private final static String FILE_NAME = "file.xml";
     
     
    	private XMLReader objxml = new XMLReader();
     
    	private PolyManager m_mainPolyMan;
    	private AxisManager m_mainAxesMan;
     
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
     
     
    		TestingProcessing TProc = new TestingProcessing();
     
    		TProc.setXMLfile(FILE_NAME);
    		TProc.setPolyMan();
    		TProc.setAxesMan();
     
    	}
     
    	public void setPolyMan(){
    		m_mainPolyMan = objxml.getPolyMan();
    	}
     
    	public void setAxesMan(){
    		m_mainAxesMan = objxml.getAxisMan();
    	}
     
    	public void setXMLfile(String fIN){
    		  System.out.println("filename: " +  fIN);
    		objxml.XMLRead(fIN);
    	}
     
    	public XMLReader getObjXML(){
    		return objxml;
    	}
     
    }

    Why is that erroring?

    Any help would be much appreciated.

    g000we


  2. #2
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Error: Null Exception on Array of classes

    Solved it..

    public class AxisManager {
    	//store axises in array
    	//store axises order (left to right)
    	private Axis[] m_axes;
    	private int[] m_axesOrder;
     
    	public void CreateAxes(int numAxesIN){
    		m_axes = new Axis[numAxesIN];
    		m_axesOrder = new int[numAxesIN];
    		for(int i = 0; i < m_axes.length; i++){
    			// m_axes[i].SetID(i);
    			System.out.println("i:"+ i); 
    			m_axes[i] = new Axis();
    			m_axesOrder[i] = i;
    			m_axes[i].SetID(i);
    		}
    	}
    }

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Error: Null Exception on Array of classes

    Well done. Beat me to it
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Null Pointer Exception Help!!
    By puzzledstudent in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 11th, 2010, 06:46 PM
  2. [SOLVED] Null Pointer Exception
    By musasabi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 11th, 2010, 09:25 PM
  3. JComboBox null pointer Exception error
    By F_Arches in forum AWT / Java Swing
    Replies: 2
    Last Post: November 29th, 2009, 02:32 PM
  4. Null Pointer Exception
    By MysticDeath in forum Exceptions
    Replies: 2
    Last Post: October 24th, 2009, 01:49 PM
  5. Getting Null Pointer Exception in runtime
    By RoadRunner in forum Exceptions
    Replies: 1
    Last Post: April 26th, 2009, 01:21 PM

Tags for this Thread