这是原码:
javac通过但java的时候出现了错误:
Exception in thread "main" java.lang.NoClassDefFoundError:DataIOException/class//DataIOException.java
import java.io.*;
class DataIOException
{
public static void main(String args[])
{
//create Inputstream with FileInputStream
try
{
DataInputStream dis = new DataInputStream(new FileInputStream("DataIOException.java"));
byte b;
//read file and print
while(true)
{
b = dis.readByte();
System.out.println((char)b);
System.out.flush();
}
}
//catch EOFException
catch(EOFException e1)
{
System.out.println(e1);
}
//catch FileNotFoundException
catch(FileNotFoundException e2)
{
System.out.println(e2);
}
//catch IOException
catch(IOException e3)
{
System.out.println(e3);
}
//catch other Exception
catch(Throwable anything)
{
System.out.println(anything);
}
}
}
javac通过但java的时候出现了错误:
Exception in thread "main" java.lang.NoClassDefFoundError:DataIOException/class//DataIOException.java
import java.io.*;
class DataIOException
{
public static void main(String args[])
{
//create Inputstream with FileInputStream
try
{
DataInputStream dis = new DataInputStream(new FileInputStream("DataIOException.java"));
byte b;
//read file and print
while(true)
{
b = dis.readByte();
System.out.println((char)b);
System.out.flush();
}
}
//catch EOFException
catch(EOFException e1)
{
System.out.println(e1);
}
//catch FileNotFoundException
catch(FileNotFoundException e2)
{
System.out.println(e2);
}
//catch IOException
catch(IOException e3)
{
System.out.println(e3);
}
//catch other Exception
catch(Throwable anything)
{
System.out.println(anything);
}
}
}
在java的时候提示:
Exception in thread "main" java.lang.NoClassDefFoundError :DataIOException/class
//DataIOException.java
import java.io.*;
class DataIOException
{
public static void main(String args[])
{
//create Inputstream with FileInputStream
try
{
DataInputStream dis = new DataInputStream(new FileInputStream("DataIOException.java"));
byte b;
//read file and print
while(true)
{
b = dis.readByte();
System.out.println((char)b);
System.out.flush();
}
}
//catch EOFException
catch(EOFException e1)
{
System.out.println(e1);
}
//catch FileNotFoundException
catch(FileNotFoundException e2)
{
System.out.println(e2);
}
//catch IOException
catch(IOException e3)
{
System.out.println(e3);
}
//catch other Exception
catch(Throwable anything)
{
System.out.println(anything);
}
}
}
Exception in thread "main" java.lang.NoClassDefFoundError :XXXXX/class
如果是这样,那么是你的环境变量没设好,导致执行时,找不到你已编译过的class文件
这和jdk没关系。
用jbuilder执行时没有问题,是因为在jbuilder环境下,已经有默认的路径了,而你编译后的class文件会被放到默认的路径下,执行时当然就不会出错了。
并且我也没有设置classpath
但是其他程序又可以运行的,我就不知道为什么了?
Exception in thread "main" java.lang.NoClassDefFoundError :XXXXX/class
的错误
就有下课的危险
你好拽啊
import java.util.*;public class datetest {
public static void main(String arg[]) {
Date date1 = new Date();
Calendar date4 = Calendar.getInstance();
long startt, allt = 0L;
int i = 0, b = 0;
startt = date4.getTimeInMillis();
echo(startt); System.out.println(date1.toString());
Date date2 = new Date(1000L);
System.out.println(date2.toString());
Date date3 = new Date();
System.out.println("现在时刻是" + date3.getYear() + date3.getDate()); echo(date4.get(Calendar.MONTH));
echo(date4.getTime().toString());
allt = date4.getTimeInMillis() - startt; echo(date4.get(Calendar.YEAR));
echo("现在时刻是" + date4.get(Calendar.YEAR) + "年" + date4.get(Calendar.MONTH) +
"月" + date4.get(Calendar.DATE) + "日" +
date4.get(Calendar.HOUR_OF_DAY) + "时" + date4.get(Calendar.MINUTE) + "分" +
date4.get(Calendar.SECOND) + "秒");
echo("执行时间" + date4.getTimeInMillis() + allt);
} //echo函数的各种定义,String int long char
//这样定义是不是太麻烦了点?????
//有没有一个可以概括所有的类型??目前是做不到的??
public static void echo(String str) {
System.out.println(str);
} public static void echo(int str) {
System.out.println(str);
} public static void echo(long str) {
System.out.println(str);
} public static void echo(char str) {
System.out.println(str);
}}
如果是classpath的问题,请问你们又如何设置classpath的?
HELLOWORLD问题[java.com.cn]
1.下载j2sdk 1.4.1rc (http://java.sun.com,建议同时下载其java/ Document,这是Java帮助文档)2.运行刚刚下载的*.exe文件进行正式安装(以下假设安装于c:\j2sdk1.4.1,建议安装路径不要有空格,不宜安装在\Program Files目录下)。3.设置运行环境参数: a.如果是Win95/98,在\autoexec.bat的最后面添加如下3行语句:JAVA_HOME=c:\j2sdk1.4.1
PATH=%JAVA_HOME%\bin;%PATH%
CLASSPATH=.;%JAVA_HOME%\lib b.如果是Win2000,使用鼠标右击“我的电脑”->属性->高级->环境变量 系统变量->新建->变量名:JAVA_HOME 变量值:c:\j2sdk1.4.1
系统变量->新建->变量名:CLASSPATH 变量值:.;%JAVA_HOME%\lib
系统变量->编辑->变量名:Path 在变量值的最前面加上:%JAVA_HOME%\bin;(CLASSPATH中有一英文句号“.”后跟一个分号,表示当前路径的意思)4.使用文本编辑器(比如:edit.com/记事本/UltraEdit/EditPlus)编写如下代码,并保存为文件:HelloWorld.java(必须大小写正确!假设为c:\test\HelloWorld.java)/* HelloWorld.java */
public class HelloWorld {
public static void main(String arg[]) {
System.out.println("Hello, World!");
}
}5.开启一个DOS窗口,CD(就是跳转/Change Directory)到HelloWorld.java所在的目录中c:\>cd \test
c:\test>_6.编译HelloWorld.java为HelloWorld.classc:\test>javac HelloWorld.java7.运行HelloWorld.classc:\test>java HelloWorld
Hello, World!c:\test>_
以后不要问我要了,只说一次了http://www.confluent.fr/javadoc/jdk14.html
都是E文的!!!!
我晕死