自己编的类引用时要用全名,但不知道为什么,eg:在C:\hcj文件夹中有包corejava,内有类Day.class,如果你的classpath中有C:\hcj,那么引用时使用import corejava.Day (Day.java中有package corejava;)。也许是java自身的问题吧,需要全名引用,不清楚的说。

解决方案 »

  1.   

    我想是你的Day.java里面一定没有 package 这语句吧,呵呵
    加上一个 package aa;
    重新编译一下试试
      

  2.   

    to yujiebo025(独舞黄纱) :
    我试过,必须用全名,当然需要用package
      

  3.   

    can not resolve symbol???
    我怎么觉得如果是classpath设置的不对,找不到类的时候应该报找不到类定义的错误呢?
    你的Clendar和Day在一个文件夹下面么? 如果在一个文件夹下,又同时声明在同一个包里面,那Clendar用Day根本不用import的,直接用就可以了~~如果Day和Clendar 不在一个文件夹下,那么你想用day就要把day 声明在一个包里面(包名要和文件夹名一样),然后再import这个包,前提是,这个文件夹的父文件夹要写在classpath里面~~
    不知道说清楚了没有
      

  4.   

    我想是你的Day.java里面一定没有 package 这语句吧,呵呵
    加上一个 package aa;
    重新编译一下试试
    up 就是这个原因
      

  5.   

    将包放在根目录就好使
    例如com.bruceeckel.tools 

    C:\com.bruceeckel.tools 
      

  6.   

    当然有package 语句啦 而且hcj下面有文件夹corejava(现在改的,原来是aa)也就是包了
      

  7.   

    "我在hcj文件夹下建了个目录aa,把Day.class拷到里面了,在Clendar.java里用了import aa.*也不能编译,classpath路径追加了c:\hcj,c:hcj\aa也试过);"Day.class 不是aa包中的,应该放在它所在的包对应的文件加内如
    package myPackage.MyClassMyClass应该放在myPackage文件夹下
    你手工拷贝过去,或编译MyClass类,自动生成包路径
      

  8.   

    ustbzhangwei(wei) :Day.class 是hcj下的corejava包中的 ,Day.java里的包是package corejava;我重新编译了,编译成功,但引用时还是报错:cannot resolve symbol,请大哥大姐们帮我解决这个问题,!!!!!!!!
      

  9.   

    各位大哥:classpath中有C:\hcj(c:\jdk1.4\lib\tools.jar;c:\jdk1.4\lib\dt.jar; c:\hcj),在C:\hcj文件夹中有包corejava,内有类Day.class,在编译时报如下错误:
    C:\hcj>javac Calendar.java
    classone.java:1: package corejavadoes not exist
    import corejava.day;
    这应是路径问题,请问大哥还要如何设置路径啊
      

  10.   

    `是这样写的嘛?
     package aa
     //...
     public class Day{}
    /**************************/
     import aa.*;
     //...
     public class Calendar{}
     //...在此类中要调用Day类
    2个.java文件不在同一个文件夹里!!
    classpath中有.;c:\jdk1.4\lib\tools.jar;c:\jdk1.4\lib\dt.jar;c:\hcj;
    你在试一试...设置中添加一个点"."
    应该没有问题啊.如果不行.你把sourc贴出来.我帮你试一试!
      

  11.   

    : tiger_wkh52741(走走.跑跑.瞧瞧!) :谢谢了package corejava;
    import java.util.*;
    import java.io.*;public class Day implements Cloneable, Serializable
    {  /**
        *  Constructs today's date
        */  
        
       public Day()
       {  GregorianCalendar todaysDate 
             = new GregorianCalendar();
          year = todaysDate.get(Calendar.YEAR);
          month = todaysDate.get(Calendar.MONTH) + 1;
          day = todaysDate.get(Calendar.DAY_OF_MONTH);
       }   /**
        * Constructs a specific date
        * @param yyyy year (full year, e.g., 1996, 
        * <i>not</i> starting from 1900)
        * @param m month
        * @param d day
        * @exception IllegalArgumentException if yyyy m d not a 
        * valid date
        */
          
       public Day(int yyyy, int m, int d) 
       {  year = yyyy;
          month = m;
          day = d;
          if (!isValid()) 
             throw new IllegalArgumentException();
       }
       
       /**
        * Advances this day by n days. For example. 
        * d.advance(30) adds thirdy days to d
        * @param n the number of days by which to change this
        * day (can be < 0)
        */
       
       public void advance(int n)
       {  fromJulian(toJulian() + n);
       }   public int getDay()
       /**
        * Gets the day of the month
        * @return the day of the month (1...31)
        */   {  return day;
       }   public int getMonth()
       /**
        * Gets the month
        * @return the month (1...12)
        */   { return month;
       }   public int getYear()
       /**
        * Gets the year
        * @return the year (counting from 0, <i>not</i> from 1900)
        */   { return year;
       }
       
       /**
        * Gets the weekday
        * @return the weekday (0 = Sunday, 1 = Monday, ..., 
        * 6 = Saturday)
        */
        
       public int weekday() { return (toJulian() + 1)% 7; }
       
       /**
        * The number of days between this and day parameter 
        * @param b any date
        * @return the number of days between this and day parameter 
        * and b (> 0 if this day comes after b)
        */
       
       public int daysBetween(Day b)
       {  return toJulian() - b.toJulian();
       }   /**
        * A string representation of the day
        * @return a string representation of the day
        */
       
       public String toString()
       {  return "Day[" + year + "," + month + "," + day + "]";
       }   /**
        * Makes a bitwise copy of a Day object
        * @return a bitwise copy of a Day object
        */
       
       public Object clone()
       {  try
          {  return super.clone();
          } catch (CloneNotSupportedException e)
          {  // this shouldn't happen, since we are Cloneable
             return null;
          }   
       }   /**
        * Computes the number of days between two dates
        * @return true iff this is a valid date
        */
        
       private boolean isValid()
       {  Day t = new Day();
          t.fromJulian(this.toJulian());
          return t.day == day && t.month == month 
             && t.year == year;
       }   private int toJulian()
       /**
        * @return The Julian day number that begins at noon of 
        * this day
        * Positive year signifies A.D., negative year B.C. 
        * Remember that the year after 1 B.C. was 1 A.D.
        *
        * A convenient reference point is that May 23, 1968 noon
        * is Julian day 2440000.
        *
        * Julian day 0 is a Monday.
        *
        * This algorithm is from Press et al., Numerical Recipes
        * in C, 2nd ed., Cambridge University Press 1992
        */
       {  int jy = year;
          if (year < 0) jy++;
          int jm = month;
          if (month > 2) jm++;
          else
          {  jy--;
             jm += 13;
          }
          int jul = (int) (java.lang.Math.floor(365.25 * jy) 
          + java.lang.Math.floor(30.6001*jm) + day + 1720995.0);      int IGREG = 15 + 31*(10+12*1582);
             // Gregorian Calendar adopted Oct. 15, 1582      if (day + 31 * (month + 12 * year) >= IGREG)
             // change over to Gregorian calendar
          {  int ja = (int)(0.01 * jy);
             jul += 2 - ja + (int)(0.25 * ja);
          }
          return jul;
       }   private void fromJulian(int j)
       /**
        * Converts a Julian day to a calendar date
        * @param j  the Julian date
        * This algorithm is from Press et al., Numerical Recipes
        * in C, 2nd ed., Cambridge University Press 1992
        */
       {  int ja = j;
       
          int JGREG = 2299161;
             /* the Julian date of the adoption of the Gregorian
                calendar    
             */         if (j >= JGREG)
          /* cross-over to Gregorian Calendar produces this 
             correction
          */   
          {  int jalpha = (int)(((float)(j - 1867216) - 0.25) 
                 / 36524.25);
             ja += 1 + jalpha - (int)(0.25 * jalpha);
          }
          int jb = ja + 1524;
          int jc = (int)(6680.0 + ((float)(jb-2439870) - 122.1)
              /365.25);
          int jd = (int)(365 * jc + (0.25 * jc));
          int je = (int)((jb - jd)/30.6001);
          day = jb - jd - (int)(30.6001 * je);
          month = je - 1;
          if (month > 12) month -= 12;
          year = jc - 4715;
          if (month > 2) --year;
          if (year <= 0) --year;
       }   private int day;
       private int month;
       private int year;
    }
    import corejava.*;public class Calendar
    {  public static void main(String[] args)
       {  int m;
          int y;  
          if (args.length == 2)
          {  m = Format.atoi(args[0]);
             y = Format.atoi(args[1]);
          }
          else
          {  Day today = new Day(); // today's date
             m = today.getMonth();
             y = today.getYear();
          }      Day d = new Day(y, m, 1); // start date of the month      System.out.println(m + " " + y);
          System.out.println("Sun Mon Tue Wed Thu Fri Sat");
          for( int i = 0; i < d.weekday(); i++ ) 
             System.out.print("    ");
          while (d.getMonth() == m)
          {  if (d.getDay() < 10) System.out.print(" ");
             System.out.print(d.getDay());
             if (d.weekday() == 6) 
                System.out.println("");
             else 
                System.out.print("  ");
             d.advance(1);
          }
          if (d.weekday() != 0) System.out.println("");
       }
    }
      

  12.   

    给你点视频教程吧:
    classpath的设置:
    http://sccnc.onlinedown.net/down/classpath.rar
    环境变量:
    http://as.onlinedown.net/down/java_hjbl.rar
    Jar的介绍与使用:
    http://as.onlinedown.net/down/java_Jar.rar解压后是rmvb格式.