2012-11-02 84 views
1

因此,我正在編寫一個編程類的代碼,用於模擬客戶可以購買產品並將其添加到購物車的網站。我製作了一個產品和購物車類。它們都在某個目錄中,並且它們的.class文件位於同一個包中。那麼爲什麼我在編譯我的Cart類時在產品上找不到符號?幫助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; 
} 

}

+0

你能發佈完整的錯誤? – kosa

+2

...以及產生它的確切線 – Vlad

+0

您是否在命令行上編譯?在日食? – thatidiotguy

回答

2

當你編譯,你必須要在上一級文件夾 - 即作爲你的包name是com.DownloadThis,你應該在「com」文件夾之上(如果你從命令行發出一個dir,你應該在結果中看到com文件夾)。

com文件夾應包含DownloadThis文件夾(名稱區分大小寫),該文件夾又必須包含您的.class文件。

+0

啊,我認爲這是問題!謝謝! – Razz

0

我能夠運行編譯從直接../com/DownloadThis/兩個文件「的javac *」