现在的作业的题目都是 给 我提供 一个class 文件 和一个未完成的java 文件
  其中 java文件要使用 那个class文件
 但是出问题了
比喻说
一个文件里面有一个A.class 和B.java
   B 要用到A.class 我直接使用的时候会提示 找不到 class  A 
A.class 和B.java 在同一个目录下
即使我 import A; 也不行
  怎么办!!!!!!!!!!

解决方案 »

  1.   

    首先确认你的classpath是不是包含当前目录 ,加上 .;再 A.class是什么包的结构,有的话,放在相应的文件结构里面,import的时候要写上包名,而且B的包结构也要弄清楚自己多试试!!
      

  2.   

    A和B有包package声明吗。怎么声明的?
      

  3.   

    classpath路径设置加上当前目录的设置.\
      

  4.   

    A 和 B 有包 package 声明所以后什么意思?
    而且A 和 B 的结构也很简单 就是   B中 new 一个 class A
    再使用 A 中的一些简单函数
      

  5.   

    如果 A.class 和 B.java
    在 D:/sss/ 

    就在classpath 里面加  “D:/sss/;”  吗?
      

  6.   

    要把A和B的包结构弄清楚,并放到对应的目录里
    classpath要把当前目录.;添上
      

  7.   

    偶还是没大懂啊!!!!!!!!
       现在就只有 一个A.class 和B.java
         从网上下载下来的
      

  8.   

    我把 那个 java 文件发来了
    import  java.io.*;
    import  java.util.*;
    /**
     * <p>This class is to simulate a shopint car  </p>
     * <p>This class will give the user 5 choice to
     * show the different informations,such as the ID,telephone ,etc
     * </p>
     *
     * <p>Copyright: JESSE (c) 2006</p>
     *
     * <p>Company: JESSE_SOFTWARE </p>
     *
     * @author JESSE8013
     * @version 1.0
     */
    public class ShoppingCartApplication  {        private static BufferedReader  stdIn =
                    new  BufferedReader(new  InputStreamReader(System.in));
            private static PrintWriter  stdOut =
                    new  PrintWriter(System.out, true);
            private static PrintWriter  stdErr =
                    new  PrintWriter(System.err, true);        private ShoppingCart cart;        /* DOCUMENT THIS PUBLIC METHOD */
    /**first initiate the class ShoppingApplication .
     * and then invoke the run function
     * IOException is thrown when error happened
     *
     *
    */
            public static void main(String[]  args) throws IOException  {                ShoppingCartApplication application = new  ShoppingCartApplication();                application.run();
            }
    /**
     * give the user four chances
     * and input 0 to end the function
     * @param cart the Object of class Shopping
     *
     */
            private void run() throws IOException  {                cart = new  ShoppingCart();                int  choice = getChoice();                while (choice != 0)  {                        if (choice == 1)  {
                                    cart.addProduct(readProduct());
                            } else if (choice == 2)  {
                                    stdOut.println(cart.toString());
                            } else if (choice == 3)  {
                                    stdOut.println(cart.getTotalValue());
                            }                        choice = getChoice();
                    }
            }        private int  getChoice() throws IOException  {                do  {                        int input;                        try  {
                                    stdErr.println();
                                    stdErr.print("[0]  Quit\n"
                                                 + "[1]  Add Product\n"
                                                 + "[2]  Display Products\n"
                                                 + "[3]  Display Total\n"
                                                 + "choice>");
                                    stdErr.flush();                                input = Integer.parseInt(stdIn.readLine());                                if (0 <= input && 3 >= input)  {                                        return  input;                                } else {
                                            stdErr.println("Invalid choice:  " + input);
                                    }
                            } catch (NumberFormatException  nfe)  {
                                    stdErr.println(nfe);
                            }        }while (true);
            }
        /**
         * make user to input a string while the model is
         * like [name]_[quantity]_[price]
         * use the StringTokenizer to decompound it into
         * three part. and the sencond part should be int and not less 0
         * and the the third part-the price shouble be double no less than 0
         *  else a wrong message vill output
         *  NumberOfFormat Exception will be catched
         *
         *
         * @return return a instanced class Product
         * @throws IOException
         */
            private Product readProduct() throws IOException {
                    final String DELIM = "_";
                    String name = "";
                    int quantity = 0;
                    double price = 0.0;
                    String productModel=new String("[name]_[quanity]_[price]");
                    do {
                    stdOut.print(productModel);
                    stdOut.flush();
                    String inputProduct=stdIn.readLine();
                    StringTokenizer stringTokenizer=new StringTokenizer(inputProduct,DELIM);
            if(stringTokenizer.countTokens()!=3){
                    stdOut.println("Invalide input,product should like this"+productModel);
                    stdOut.flush();
            }
            else{
                    name=stringTokenizer.nextToken();
                    try{
                            quantity=Integer.parseInt(stringTokenizer.nextToken());
                            price=Double.parseDouble(stringTokenizer.nextToken());
                            if(quantity<0||price<0){
                            if(quantity<0)
                                    stdOut.println("Quantity should not less than 0");
                            if(price<0)
                                    stdOut.println("price should not less than 0");
                            }
                            else
                            return new Product(name, quantity, price);
                    }
                    catch(NumberFormatException e){
                            stdErr.println(e.toString());
                    }
            }
        }
            while(true);
    }
    }
      

  9.   

    首先确定那个A.class是不是带了什么packet名,那样你肯定就调用不到,最好是找到A的源文件,找不到就反编译!
      

  10.   

    A.class 没有带什么packet
       反编译 是可以
    但这总是麻烦
       难道   给一个class 文件 就不能使用吗???
      

  11.   

    至少要知道A的包结构啊 才可以import进来
      

  12.   

    用java反编译软件把那个class反编译,比如dj java decompiler ,然后看看class的包结构,再把那个class加到classpath就ok了
      

  13.   

    刚才用eclipse跑了下,好像不止少一个类,少Product跟ShoppingCart两个类
      

  14.   

    给一个class是当然也能使用,但问题是现在你的class不在正确的位置上,假如A.class里边没有包结构,把A.class和B.java放在同一个目录里并且你的classpath里包括.;应该就能找到Class A了,但假如A里边有包结构的话,那就不好说了,如果你确定A里边没有包结构,那么仔细检查你的classpath
      

  15.   

    A.class的文件和class A的文件是两码事.
      

  16.   

    反编译,看一下A.class的package在哪里,然后修改classpath环境变量,与之对应
      

  17.   

    我觉得是A.class的问题,假如A.java里面调用了packet语句,例如:packet org;那样的话调用A的时候,应该是org.A
      

  18.   

    如果A.class所对应的文件是yuanma.java,而yuanma.java编译后生成yuanma.class,你再将yuanma.class改为A.class,那当然你就用不了了。
      

  19.   

    有可能A.class有自己的包结构,比如A.class这个类的完整包名是com.seeshine.A,那么你在B中引用的时候就不能直接import A,而应该是import com.seeshine.A!!!