Topic: 帮忙看看错在哪

  Print this page

1.帮忙看看错在哪 Copy to clipboard
Posted by: lymhappy123
Posted on: 2008-11-19 20:39

源程序代码如下:,文件路径是F:\java1

import java.util.*;
class CalendarTest {
  public static void main(String args[]) {
    Calendar calendar = Calendar.getInstance();
   calendar.setTime(new Date());
   String 年 = String.valueOf(calendar.get(Calendar.YEAR)),
          月 = String.valueOf(calendar.get(Calendar.MONTH)+1),
          日 = String.valueOf(calendar.ger(Calendar.DAY_OF_MONTH)),
          星期 = String.valueOf(calendar.get(Calendar.DAY_OF_WEEK)-1);
   int hour = calendar.get(Calendar.HOUR_OF_DAY),
   minute = calendar.get(Calendar.MINUTE),
   second = calendar.get(Calendar.SECOND);  
    System.out.println("现在的时间是:");
    System.out.println(""+年+"年"+月+"月"+日+"日"+"星期"+星期);
    System.out.println(""+hour+"时"+minute+"分"+second+"秒");
    calendar.set(1962,5,29);
    long time1962 = calendar.getTimeInMillis();
    calendar.set(2006,9,1);
    long time2006 = calendar.getTimeInMillis();
    long 相隔天数 = (time2006-time1962)/(1000*60*60*24);
    System.out.println("2006年10月1日和1962年6月29日相隔"+相隔天数+"天");
  }
}


运行后错误如下图

环境变量设置如下:
classpath是 .;C:\jdk1.6.0_03\jre\lib\rt.jar;
Path是 C:\jdk1.6.0_03\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem

未命名.gif (240.05k)

2.Re:帮忙看看错在哪 [Re: lymhappy123] Copy to clipboard
Posted by: micsolaris
Posted on: 2008-11-20 00:50

我这边测试过了没问题,但是
日 = String.valueOf(calendar.ger(Calendar.DAY_OF_MONTH)),
这里的get错了。

还有就是你用的jdk是1.6吧。那么path里应该是C:\Program Files\Java\jdk1.6.0\bin

C:\jdk1.6.0_03\bin;里应该没有javac。建议重新设置了path后,重新编译后测试下。还有就是别用中文命名变量啦。

3.Re:帮忙看看错在哪 [Re: lymhappy123] Copy to clipboard
Posted by: lymhappy123
Posted on: 2008-11-20 13:22

先谢谢你了 ,不过 我把path设成C:\Program Files\Java\jdk1.6.0\bin
以后就'javac不是内部或者外部命令',也不是可运行的程序或批处理文件。
我看了一下,我的C:\jdk1.6.0_03\bin;里javac.exe···

4.Re:帮忙看看错在哪 [Re: lymhappy123] Copy to clipboard
Posted by: micsolaris
Posted on: 2008-11-20 13:49

'javac不是内部或者外部命令'是因为你的JDK的路径根本不是C:\Program Files\Java\jdk1.6.0,如果默认的是C:\Program Files\Java\jdk1.6.0\bin
。但是如果自己当时选择了的话那应该是%JAVA_HOME%\bin

5.Re:帮忙看看错在哪 [Re: lymhappy123] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2008-11-22 01:05

micsolaris wrote:
'javac不是内部或者外部命令'是因为你的JDK的路径根本不是C:\Program Files\Java\jdk1.6.0,如果默认的是C:\Program Files\Java\jdk1.6.0\bin
。但是如果自己当时选择了的话那应该是%JAVA_HOME%\bin

Generally speaking, JDK could be installed anywhere. Hence it makes sense to set up the system environment JAVA_HOME. However, it is not the problem that caused your program to fail.

You can do the following:
- check your directory F:\java1, make sure that there are no existing classes or other unrelated java file.
- recompile the code using another JDK.
- using some IDE like eclipse for trouble shooting.

Jiafan

6.Re:帮忙看看错在哪 [Re: lymhappy123] Copy to clipboard
Posted by: lymhappy123
Posted on: 2008-11-23 12:54

谢谢


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923