Razz
Razz

Reputation: 11

"Cannot Find Symbol" Why?

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;
}

}

Upvotes: 1

Views: 149

Answers (2)

Dan Iliescu
Dan Iliescu

Reputation: 435

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

Upvotes: 0

thedayofcondor
thedayofcondor

Reputation: 3876

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.

Upvotes: 2

Related Questions