我的jdk怎么了?

caffv 2000-08-17 09:21:00
我从sun下了jdk 那装后,将环境变量配完毕。
从另一家站点下了api样例。javac Main.java
编译通过,java Main 出现:Exception in thread"main"
java.lang.NoClassDefFoundError:Main的错误。
我以为是例子的错误,自己写了一个HelloWorld.java
javac HelloWorld.java没问题。
java HelloWorld 还是该例外,请问是怎么回事。
...全文
182 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
skt985 2001-06-01
  • 打赏
  • 举报
回复
17360关注!
chenjp 2000-08-17
  • 打赏
  • 举报
回复
$JavaHome\bin和$JavaHome\jre\lib\rt.jar
只是JDK提供的标准库,
你要运行自己的程序,当然要自己的*.class包含到CLASSPATH中才可以。
以后自己的class多了,可以用jar命令作成package(*.jar),然后把此*.jar文件放到你的CLASSPATH中。
leslielu 2000-08-17
  • 打赏
  • 举报
回复
我知道了,一定是你的classpath里没有当前目录!
呵呵,加一个 “.\;" in your classpath.
caffv 2000-08-17
  • 打赏
  • 举报
回复
谢谢你,success!!
不是将$JavaHome\bin和$JavaHome\jre\lib\rt.jar加入classpath就行吗?
为何*.class也需要,请详述
lowhand 2000-08-17
  • 打赏
  • 举报
回复
十之八九是classpath的問題,你的文件是否在classpath中包括的路徑里?
caffv 2000-08-17
  • 打赏
  • 举报
回复
我现在觉得可能jdk1.2.2装的有问题
leslielu 2000-08-17
  • 打赏
  • 举报
回复
建议你这样
public class Main{
}
我的JDK1.1.7是可以执行你上面的Main的。
编译,执行都没有问题。
caffv 2000-08-17
  • 打赏
  • 举报
回复
我把你的HelloWorld存成HelloWorld.java
javac HelloWorld.java通过
java HelloWorld
还是该例外
caffv 2000-08-17
  • 打赏
  • 举报
回复
HelloWorld.java 如下:
import java.io.*;

public class HelloWorld{
public static void main(String args[]){
System.out.println("Hello World");
}
}

Main.java 如下:

/*
// START array
// Implementation of String.getChars().
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
System.arraycopy(value, offset + srcBegin, dst, dstBegin,
srcEnd - srcBegin);
}
// END array
*/

import java.util.Date;
import java.util.Properties;
import java.util.Enumeration;
import java.io.*;

class Main {
// START err
public static void usage() {
System.err.println("Usage: testprog <username> <age>");
System.exit(-1);
}
// END err

// START in
// reads a line from standard input
public static String getLine() {
StringBuffer buf = new StringBuffer(80);
int c;
try {
while ((c = System.in.read()) != -1) {
char ch = (char) c;
if (ch == '\n')
break;
buf.append(ch);
}
} catch (IOException e) {
System.err.println(e);
}
return (buf.toString());
}
// END in

public static void setIO() {
try {
// START setIO
System.setIn(new java.io.FileInputStream("myinputfile"));
System.setOut(new PrintStream(new java.io.FileOutputStream("myoutputfile")));
System.setErr(new PrintStream(new java.io.FileOutputStream("myerrinputfile")));

System.out.println("Hello there file"); // using new out
System.err.println("Hello there err file"); // using new err
// END setIO

} catch (java.io.IOException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
// START date
// Create a Date object using today's date
Date today = new Date(System.currentTimeMillis());
System.out.println("Today: " + today.toString());
// END date
{
// START getprops
Properties props = System.getProperties(); // get list of properties
// Print properties using Enumeration
for (Enumeration enum = props.propertyNames(); enum.hasMoreElements();) {
String key = (String)enum.nextElement();
System.out.println(key + " = " + (String)(props.get(key)));
}
// END getprops
setIO();
}
{
// START getprop
// get user's home directory
String homeDir = System.getProperty("user.home");
// If 'outDir' not found, use 'homeDir' as default
String outDir = System.getProperty("testdir", homeDir);
// END getprop
System.out.println("homeDir: " + homeDir);
System.out.println("outDir: " + outDir);
}
/*
// START getsec
// Implementation of Thread.checkAccess()
public final void checkAccess() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkAccess(this);
}
}
// END getsec
*/
{
String s1 = getLine();
System.out.println("in: " + s1);
}
{
// START setprops
Properties props = System.getProperties();
// Add 'outDir' property
props.put("outDir", "/tmp");
// overwrites System properties with new properties
System.setProperties(props);
// END setprops
System.out.println("outDir: " + System.getProperty("outDir"));
}

usage();
}
}

元明 2000-08-17
  • 打赏
  • 举报
回复
java.lang是一个特殊的类库,她会自动导入每个Java File.在此我提供给你一个简单的
Hello World例程,看是否和你的一样.
附:
//:HelloWorld.java
import java.util.*;
public class HelloWorld
{
public static void main(String[] args) {
String pzzStr1;
String pzzStr2;
String pzzStr3;
pzzStr1 = args[0];
pzzStr2 = args[1];
pzzStr3 = args[2];
System.out.println("Hello world!");
System.out.println(pzzStr1 + " " + pzzStr2 + " " + pzzStr3);
}
}///:~
leslielu 2000-08-17
  • 打赏
  • 举报
回复
帖出你的源程序就知道了。
1by1 2000-08-17
  • 打赏
  • 举报
回复
Main.java 中有class没有找到.注意大小写的问题
lowhand 2000-08-17
  • 打赏
  • 举报
回复
i agree with people above ,sorry i can't input chinese now
caffv 2000-08-17
  • 打赏
  • 举报
回复
谢谢!!谢谢大家!!这真是个学习的天堂

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧