Java &引用;找不到符号“;为什么?

Java &引用;找不到符号“;为什么?,java,Java,因此,我正在为一个编程类编写代码,该类模拟一个网站,客户可以在该网站上购买产品并将其添加到购物车中。我制作了一个产品和购物车类。它们都在some目录中,并且它们的.class文件在同一个包中。那个么,为什么在编译购物车类时,我会在产品上看到“找不到符号”?救命啊!还有泰 购物车类别: package com.DownloadThis; import java.util.ArrayList; public class Cart { private ArrayList<Product&g

因此,我正在为一个编程类编写代码,该类模拟一个网站,客户可以在该网站上购买产品并将其添加到购物车中。我制作了一个产品和购物车类。它们都在some目录中,并且它们的.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) {


}
}

}

编译时,您必须位于上层文件夹中-即,由于您的包名为com.download,因此您应该位于“com”文件夹的上方(如果从命令行发出dir,您应该在结果中看到com文件夹)


com文件夹应包含DownloadThis文件夹(名称区分大小写),该文件夹必须包含您的.class文件。

我可以直接从../com/DownloadThis/运行“javac*”编译这两个文件。

您能发布完整错误吗?。。。以及您在命令行上编译的具体行?在eclipse中?在旁注中,不需要
objectobj=myCart.get(i);产品p=(产品)obj
,您可以直接编写为
productp=myCart.get(i)。啊,我想这就是问题所在!谢谢
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;
}