Reputation: 1
I am working on an assignment, and I have hit one roadblock. I am simply calling a string array from another class. The code in the other class (named ProductDB) is this:
public String[] inventory = {"java", "jsps", "mcb2", "txtp"};
And in the main application class (named ProductApp) I have this code:
public static void showCodes()
{
System.out.print(" Select from");
System.out.print(" => ");
for (String show : productDB.inventory)
{
System.out.print(show.toUpperCase() + " ");
}
System.out.print(" <=");
}
The error I am getting with productDB
is 'Cannot find symbol'
(I am using NetBeans).
I need to instantiate a variable named productDB
correct? How do I do this within the ProductApp
class level?
Upvotes: 0
Views: 97
Reputation: 425
You can set inventory
to static
, which makes it possible to call it in other classes by ProductDB.inventory
.
If you want to use it as you are now, with an instance of ProductDB, simply create an instance variable in class ProductApp (which must be static, since your method is static).
static ProductDB productDB = new ProductDB();
Upvotes: 2
Reputation: 31161
If your productDB
is a class, you will need to declare the inventory
member static
.
Upvotes: 0