1

そこで、顧客が製品を購入してカートに追加できるWebサイトをシミュレートするプログラミングクラスのコードを作成しています。製品とカートのクラスを作成しました。それらは両方ともいくつかのディレクトリにあり、それらの.classファイルは同じパッケージにあります。それでは、カートクラスをコンパイルするときにProductに「シンボルが見つかりません」と表示されるのはなぜですか?plzを助けて!とty

カートクラス:

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) {


}
}

製品クラス:

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

2 に答える 2

2

コンパイルするときは、上位レベルのフォルダーにいる必要があります。つまり、パッケージ名が com.DownloadThis であるため、「com」フォルダーの上にある必要があります (コマンド ラインから dir を発行すると、com フォルダーが表示されるはずです)。結果で)。

com フォルダーには DownloadThis フォルダー (名前は大文字と小文字が区別されます) が含まれている必要があり、このフォルダーには .class ファイルが含まれている必要があります。

于 2012-11-02T18:56:12.820 に答える
0

「javac*」を実行することにより、直接../com/DownloadThis/から両方のファイルをコンパイルできます。

于 2012-11-02T19:08:09.353 に答える