Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Array of objects

807591Mar 28 2008 — edited Mar 28 2008
I want to make an array of objects, storing variables by referering to array index.
This is what I've written of code so far. Running this will create a NullPointerException
public class Company {
	
	private String owner;
	private double income;
	
	public Company(String company)
	{
		//Unsure whether i need constructor?
	}
	public void setOwner(String company)
	{
		owner = company;	//Set the value for owner in given arrray object
	}
	
	public void setIncome(double income)
	{
		this.income += income;
	}
	
	public String returnOwner()
	{
		return owner;
	}
	
}

public class Marked {
	
	public static void main(String args[]){
	Company[][] owner = new Company[15][20];
	
	owner[0][0].setOwner("CompanyName");
	System.out.println("Content of Comapny[" + 0 + "][" + 0 + "] is " + owner[0][0].returnOwner() + " !");
	
	}
}
Any suggestions on what to do next will be much appreciated!
If you're not sure what I'm trying to do, please tell and I will try to explain further.
Thanks for any help in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2008
Added on Mar 28 2008
4 comments
114 views