I am trying to create an array of objects, the objects are made in a separate class (CreateObject) with getters and setters and such, and I have tested that code and it all works the way I want it to. However I am having issues trying to work out the best way to store those individual objects in my array. Any help on the matter would be greatly appreciated. I have added what I believe to be the relevant code below.
I keep getting back this error:Code:private static void processLine(String csvRow, int lineNum)
{
/**************************************
* Using split() parsing known-format *
**************************************/
// Would be good to split csvRow in CreateObject
String key, brand, model, weight, price, strKey, strBrand, strModel;
int intWeight;
double dblPrice;
String[] tokens;
tokens=csvRow.split(",");
key=tokens[0];
brand=tokens[1];
model=tokens[2];
weight=tokens[3];
price=tokens[4];
System.out.println("Key:"+key+" Brand:"+brand+" Model:"+model+" Weight:"+weight+" Price:"+price);
//Use CreateObject
strKey=new CreateObject(key, brand, model, weight, price).getKey();
strBrand=new CreateObject(key, brand, model, weight, price).getBrand();
strModel=new CreateObject(key, brand, model, weight, price).getModel();
intWeight=new CreateObject(key, brand, model, weight, price).getWeight();
dblPrice=new CreateObject(key, brand, model, weight, price).getPrice();
//System.out.println("strKey:"+strKey+" strBrand:"+strBrand+" strModel:"+strModel+" intWeight:"+intWeight+" dblPrice:"+dblPrice);
loadArray(strKey, strBrand, strModel, intWeight, dblPrice, lineNum);
}
private static void loadArray(String strKey, String strBrand, String strModel, int intWeight, double dblPrice, int lineNum)
{
CreateObject[] array;
array=new CreateObject[5];
array[lineNum-1]=new CreateObject(strKey, strBrand, strModel, intWeight, dblPrice);
System.out.println("Index 0: "+array[0]+" index 1: "+array[1]+" index 2: "+array[2]+" index 3: "+array[3]+" index 4: "+array[4]);
}
where line 274 is the 3rd last line.Quote:
LoadRecordsIntoArray.java:274: cannot find symbol
symbol : constructor CreateObject(java.lang.String,java.lang.String,jav a.lang.String,int,double)
location: class CreateObject
array[lineNum-1]=new CreateObject(strKey, strBrand, strModel, intWeight, dblPrice);
^
1 error
At one point I tried splitting line in CreateObject and it worked to an extent, but in my System.out.println (the last line of the code) it kept giving me this:
I thought maybe that was a good thing and I was just missing how to get the value at what appears to be an address?Quote:
Enter file name:
DataFive.csv
Index 0: CreateObject@eb42cbf index 1: null index 2: null index 3: null index 4: null
Index 0: null index 1: CreateObject@56e5b723 index 2: null index 3: null index 4: null
Index 0: null index 1: null index 2: CreateObject@35a8767 index 3: null index 4: null
Index 0: null index 1: null index 2: null index 3: CreateObject@2c6f7ce9 index 4: null
Index 0: null index 1: null index 2: null index 3: null index 4: CreateObject@4b71bbc9
