一个关于创建java包的问题(真的无奈,求助)
一个关于创建java包的问题
问题愚蠢,都不好意思拿到这上面来问,但实在没有办法,我搞了一个下午了,都没有弄明白是怎么
回事情呢。
我用的是java2 sdk j2sdk-1_4_2_04
运行环境是win2000server
还安装了一个JCreator
这里有三个*.java文件,是21天学会java上的例程,
——————————————————————————————————————
package com.prefect.ecommerce;
import java.util.*;
public class Item implements Comparable {
private String id;
private String name;
private double retail;
private int quantity;
private double price;
Item(String idIn, String nameIn, String retailIn, String quanIn) {
id = idIn;
name = nameIn;
retail = Double.parseDouble(retailIn);
quantity = Integer.parseInt(quanIn);
if (quantity > 400)
price = retail * .5D;
else if (quantity > 200)
price = retail * .6D;
else
price = retail * .7D;
price = Math.floor( price * 100 + .5 ) / 100;
}
public int compareTo(Object obj) {
Item temp = (Item)obj;
if (this.price < temp.price)
return 1;
else if (this.price > temp.price)
return -1;
return 0;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public double getRetail() {
return retail;
}
public int getQuantity() {
return quantity;
}
public double getPrice() {
return price;
}
}
——————————————————————————————————————
ackage com.prefect.ecommerce;
import java.util.*;
public class Storefront {
private LinkedList catalog = new LinkedList();
public void addItem(String id, String name, String price,
String quant) {
Item it = new Item(id, name, price, quant);
catalog.add(it);
}
public Item getItem(int i) {
return (Item)catalog.get(i);
}
public int getSize() {
return catalog.size();
}
public void sort() {
Collections.sort(catalog);
}
}
——————————————————————————————————————
import com.prefect.ecommerce.Storefront; //1
import com.prefect.ecommerce.Item; //2
public class GiftShop { //3
public static void main(String[] arguments) { //4
Storefront store = new Storefront(); //5
store.addItem("C01", "MUG", "9.99", "150"); //6
store.addItem("C02", "LG MUG", "12.99", "82");
store.addItem("C03", "MOUSEPAD", "10.49", "800");
store.addItem("D01", "T SHIRT", "16.99", "90");
store.sort();
for (int i = 0; i < store.getSize(); i++) {
Item show = (Item)store.getItem(i);
System.out.println("\nItem ID: " + show.getId() +
"\nName: " + show.getName() +
"\nRetail Price: $" + show.getRetail() +
"\nPrice: $" + show.getPrice() +
"\nQuantity: " + show.getQuantity());
}
}
}
——————————————————————————————————————
ok,一点问题都没有,调试通过,并且生成文件夹com\prefect\ecommerce\
但是把上面第三个文件的1、2行的代码改成如下:
import com.prefect.ecommerce.*;
问题就出来了,提示的错误为:
C:\j2sdk14204\shicao\chapter6\GiftShop.java:7: cannot access Storefront
bad class file: C:\j2sdk14204\shicao\chapter6\Storefront.java
file does not contain class Storefront
Please remove or make sure it appears in the correct subdirectory of the classpath.
Storefront store = new Storefront();
^
1 error
Process completed.
真的傻眼,实在不知道是怎么回事情呢,
还有,当我把com\prefect\ecommerce\ 文件夹整个移到C盘下,即:
C:\com\prefect\ecommerce\ 然后设置一个环境变量calsspath,它的值分别设置成:
C:\com
C:\com\prefect
C:\com\prefect\ecommerce
时,其结果都是一样的,提示的错误是:
C:\j2sdk14204\shicao\chapter6\GiftShop.java:3: package com.prefect.ecommerce does not
exist
import com.prefect.ecommerce.*;
^
C:\j2sdk14204\shicao\chapter6\Storefront.java:15: cannot resolve symbol
symbol : class Item
location: class com.prefect.ecommerce.Storefront
public Item getItem(int i) {
^
C:\j2sdk14204\shicao\chapter6\GiftShop.java:7: cannot access Storefront
bad class file: C:\j2sdk14204\shicao\chapter6\Storefront.java
file does not contain class Storefront
Please remove or make sure it appears in the correct subdirectory of the classpath.
Storefront store = new Storefront();
^
3 errors
Process completed.
第一次玩java,很多东西都不明白,求助,而且实在是弄不出来,才到这里发这样弱智的帖子