1

So I am writing code for a programming class that simulates a website where customers can buy Products and add them to a Cart. I have made a Product and Cart class. They are both in the some directory and their .class files are in the same package. So why am I getting "cannot find symbol" on Product when compiling my Cart class? Help plz! and ty

Cart class:

package com.DownloadThis; import java.util.ArrayList; public class Cart { private ArrayList<Product> myCart; public Cart() { myCart = new ArrayList<Product>(); } public void addProduct(Product p) { myCart.add(p); } public float getTotal() { float totalPrice = 0; for(int i = 0; i < myCart.size(); i++) { Object obj = myCart.get(i); Product p = (Product)obj; totalPrice = totalPrice + p.getPrice(); } return totalPrice; } public void addToCart(int product_id) { } } 

Product class:

package com.DownloadThis; import java.sql.*; public class Product { private String artist; private String album; private int year; private String genre; private float price; private String albumart; private String username; private String password; private Connection connection = null; private ResultSet rs = null; private Statement st = null; public Product() { } public Product(String artist, String album, int year, String genre, float price, String albumart) { this.artist = artist; this.album = album; this.year = year; this.genre = genre; this.price = price; this.albumart = albumart; } public String getArtist() { return this.artist; } public void setArtist(String artist) { this.artist = artist; } public String getAlbum() { return this.album; } public void setAlbum(String album) { this.album = album; } public int getYear() { return this.year; } public void setYear(int year) { this.year = year; } public String getGenre() { return this.genre; } public void setGenre(String genre) { this.genre = genre; } public float getPrice() { return this.price; } public void setPrice(float price) { this.price = price; } public String getAlbumart() { return this.albumart; } public void setFilename(String albumart) { this.albumart = albumart; } 

}

4
  • Can you post full error? Commented Nov 2, 2012 at 18:53
  • 2
    ... together with the exact line producing it Commented Nov 2, 2012 at 18:53
  • Are you compiling on the command line? In eclipse? Commented Nov 2, 2012 at 18:54
  • On the side note, there is no need of Object obj = myCart.get(i); Product p = (Product)obj;, You can directly write as Product p = myCart.get(i);. Commented Nov 2, 2012 at 18:58

2 Answers 2

2

When you compile, you have to be in the upper level folder - ie, as your package name is com.DownloadThis, you should be above the "com" folder (if you issue a dir from the command line you should see the com folder in the results).

The com folder should contain the DownloadThis folder (the name is case sensitive), which in turn must contain your .class files.

Sign up to request clarification or add additional context in comments.

1 Comment

Ahhh, I think that was the issue! Thanks!
0

I am able to compile both files from the directly ../com/DownloadThis/ by running "javac *"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.