java creating

Hi Guys, I am a nob to this so sorry if I am incorrect in terminology.

So I have a variable int j, which I set to 0
I have a variable String tempS which I place a value in here, say e0, e1, e2 etc etc for a loop

I want to use the constructor method from the class Clipmap  and I want to dynamically create new objects, named e0 etc...

how can I do this?

for (CellEntry cell : cellFeed.getEntries()) {
     tempS = "e" + Integer.toString(j);
     Clipmap <tempS> = new Clipmap(cell.getCell().getValue());
     j++;
}

Open in new window

adamc817Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
That's not possible, you should probably use  Clipmap[] or List<Clipmap>
0
adamc817Author Commented:
The problem is if I make it an array I would have to use a multi dimensional and some data is text other is string (I would like not to keep it all in string)

A ArrayList is flat correct?


You can't dynamically make constructors, that is so sad :(
0
CEHJCommented:
Then you need an array or List of a dedicated class that can hold all the data your require
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

adamc817Author Commented:
Ohhh, that sounds awesome! :)

to keep things simple:

My constructor in Clipmap class:
	public Clipmap(String n, String v, int s, int m, int y, int d){
		name = n;
		version = v;
		dbSize = s;
		month = m;
		day = d;
		year = y;
	}

Open in new window



Example of a set:
	public void setName(String n){
		name =n;
	}

Open in new window



I try (to keep it simple):

Clipmap [] mylist = new Clipmap[3];

mylist[1].setName("hi");

Open in new window


I get:
Exception in thread "main" java.lang.NullPointerException
      at MySpreadsheetIntegration.main(MySpreadsheetIntegration.java:56)

56 is the line where I try and use the set, I don't think I can use the constructor can I?
0
adamc817Author Commented:
figured it out                                      

 Clipmap [] a = new Clipmap[3];
a[0] = new Clipmap("hi");      

give me a few and think i'll close this out.
0
CEHJCommented:
Your class should probably look like the following, allowing you to have Clipmap[] or List<Clipmap>:

public class Clipmap {
    private String name;
    private String version;
    private int dbSize;
    private int month;
    private int year;
    private int day;

    public Clipmap() {
    }

    public Clipmap(String name, String version, int dbSize, int month,
        int year, int day) {
        this.name = name;
        this.version = version;
        this.dbSize = dbSize;
        this.month = month;
        this.year = year;
        this.day = day;
    }

    public String getName() {
        return this.name;
    }

    public String getVersion() {
        return this.version;
    }

    public int getDbSize() {
        return this.dbSize;
    }

    public int getMonth() {
        return this.month;
    }

    public int getYear() {
        return this.year;
    }

    public int getDay() {
        return this.day;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public void setDbSize(int dbSize) {
        this.dbSize = dbSize;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public String toString() {
        return String.format("%s=%s,%s=%s,%s=%d,%s=%d,%s=%d,%s=%d", "name",
            name, "version", version, "dbSize", dbSize, "month", month, "year",
            year, "day", day);
    }
}

Open in new window

0
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.