简单的问题,麻烦看下 我用myeclipse帮别人改完代码,由于朋友的老师只允许用原始的javac编译我就去工程目录下找到.java文件然后JAVAC编译不了。。去运行ECLIPSE生成的.class文件也不行有高手知道原因么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 环境配置里面.;C:\Program Files\Java\jdk1.5\lib\tools.jar;C:\Program Files\Java\jdk1.5\lib\dt.jar;C:\Program Files\java\jdk1.5\jre\lib看看前面是不是少个 .; 配置 java文件写包名了?贴出来看看 代码如下,在myeclipse里建立工程弄进去可以运行的起来。但是如果用个记事本,用原始的javac可以编译,但是无法运行。试了3台机器都有问题;有兴趣的朋友可以弄去帮我看下。package planeInformation;import java.awt.*;import java.awt.event.*;import java.io.*;public class MainTest { public static void main(String[] args) { new PlaneInformation(); }} //第二个类有点长,分两次发class PlaneInformation implements ActionListener { Frame mainFrame; Frame inputFrame; Frame searchFrame; TextArea plaInfo; Label lb[] = new Label[4]; Label lb2[] = new Label[2]; TextField tf[] = new TextField[4]; TextField tf2[] = new TextField[2]; Button btn[] = new Button[3]; Button btn2[] = new Button[2]; Panel p1, p2, p3, p4; IOOperation ioo; Plane pla; Plane plane[] = new Plane[100]; public PlaneInformation() { /** * 构造函数,初始话主窗口信息 set mainframe */ mainFrame = new Frame("PlaneInformation"); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // 菜单栏File选项添加 MenuItem item1 = new MenuItem("Record"); MenuItem item2 = new MenuItem("Search"); MenuItem item3 = new MenuItem("Modify"); MenuItem item4 = new MenuItem("Exit"); MenuItem item5 = new MenuItem("About"); item1.addActionListener(this); item2.addActionListener(this); item3.addActionListener(this); item4.addActionListener(this); item5.addActionListener(this); Menu menu1 = new Menu("File"); menu1.add(item1); menu1.add(item2); menu1.add(item3); menu1.addSeparator(); menu1.add(item4); Menu menu2 = new Menu("Help"); menu2.add(item5); MenuBar mb = new MenuBar(); mb.add(menu1); mb.add(menu2); mainFrame.setMenuBar(mb); // 文本框控制区域设置 plaInfo = new TextArea(); plaInfo.setFont(new Font("serif", Font.PLAIN, 18));// 字体格式 mainFrame.add(plaInfo); mainFrame.setSize(400, 250);// 大小 mainFrame.setLocation(200, 100);// 位置 mainFrame.setVisible(true);// 显示Frame /** * 记录飞机信息的窗口设置 */ inputFrame = new Frame(); inputFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { inputFrame.setVisible(false); } }); p1 = new Panel(new GridLayout(4, 2)); p2 = new Panel(); String lbname[] = { "FlightNumber:", "StartCity:", "Destination:", "FlightTime" }; String btnname[] = { "Save", "Delete", " Exit " }; // Record窗口中各字段名称、按钮设置 for (int i = 0; i < 4; i++) { lb[i] = new Label(lbname[i]); tf[i] = new TextField(15); p1.add(lb[i]); p1.add(tf[i]); } for (int i = 0; i < 3; i++) { btn[i] = new Button(btnname[i]); btn[i].addActionListener(this); p2.add(btn[i]); } btn[2].setActionCommand("input");// **用来获取对象的标签或事先为这个对象设置的命令名**// inputFrame.add(p1, BorderLayout.CENTER); inputFrame.add(p2, BorderLayout.SOUTH); inputFrame.pack(); inputFrame.setLocationRelativeTo(mainFrame); /** * set searchFrame which is used to search plane information */ searchFrame = new Frame("Search plane"); searchFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { searchFrame.setVisible(false); } }); p3 = new Panel(new GridLayout(2, 2)); p4 = new Panel(); String lbname2[] = { "FlightNumber :", "StartCity:" }; String btnname2[] = { "Search", " Exit " }; for (int i = 0; i < 2; i++) { lb2[i] = new Label(lbname2[i]); tf2[i] = new TextField(15); p3.add(lb2[i]); p3.add(tf2[i]); } for (int i = 0; i < 2; i++) { btn2[i] = new Button(btnname2[i]); btn2[i].addActionListener(this); p4.add(btn2[i]); } btn2[1].setActionCommand("search"); searchFrame.add(p3, BorderLayout.CENTER); searchFrame.add(p4, BorderLayout.SOUTH); searchFrame.pack(); searchFrame.setLocationRelativeTo(mainFrame); /** * IO operation object */ ioo = new IOOperation(); plane = ioo.getAllPlane(); } public void actionPerformed(ActionEvent e) { /** * 按钮功能实现 */ if (e.getSource() instanceof MenuItem) { MenuItem mi = (MenuItem) e.getSource(); if (mi.getLabel().equals("Record")) {// 如果点击Record inputFrame.setTitle("Record"); inputFrame.setSize(200, 200); for (int i = 0; i < 4; i++) tf[i].setText(""); p2.remove(btn[1]);// 如果是记录信息,删除‘删除’按钮 btn[0].setActionCommand("input");// 按钮‘保存’功能实现 inputFrame.setVisible(true); } else if (mi.getLabel().equals("Search")) { searchFrame.setVisible(true); } else if (mi.getLabel().equals("Modify")) { inputFrame.setTitle("Modify"); if (pla != null) {// 修改信息时,文本框信息显示 tf[0].setText(pla.getFlightNumber()); tf[1].setText(pla.getStartCity()); tf[2].setText(pla.getDestination()); tf[3].setText(pla.getFlightTime()); } p2.remove(btn[2]); p2.add(btn[1]); p2.add(btn[2]); btn[0].setActionCommand("modify"); inputFrame.setVisible(true); } else if (mi.getLabel().equals("Exit")) System.exit(0); else if (mi.getLabel().equals("About")) { final Dialog progInfo = new Dialog(mainFrame, "ProgInfo", true); progInfo.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { progInfo.dispose(); } }); progInfo.setLayout(new FlowLayout()); Label l = new Label("Plane Information System"); progInfo.add(l); progInfo.setSize(200, 80); progInfo.setLocationRelativeTo(mainFrame); progInfo.setVisible(true); } } /** * Button action */ else { Button btn = (Button) e.getSource(); if (btn.getLabel().equals("Save")) {// 点击保存时,个文本框必须非空 if (!tf[0].getText().equals("") && !tf[1].getText().equals("") && !tf[2].getText().equals("") && !tf[3].getText().equals("")) { Plane p = new Plane(); // Plane p = new Plane(tf[0].getText(), tf[1].getText(), // tf[2] // .getText(), tf[3].getText()); p.setFlightNumber(tf[0].getText()); p.setStartCity(tf[1].getText()); p.setDestination(tf[2].getText()); p.setFlightTime(tf[3].getText()); System.out.println(p.getFlightNumber()); if (btn.getActionCommand().equals("input")) { for (int i = 0; i < plane.length; i++) { if (plane[i] == null) { plane[i] = p; System.out.println(p.getFlightNumber()); break; } } ioo.write(plane); } else { for (int i = 0; i < plane.length; i++) { if (plane[i].equals(pla)) { plane[i] = p; break; } } ioo.write(plane); } } inputFrame.setVisible(false); plaInfo.setText(""); } else if (btn.getLabel().equals("Delete")) { int index = 200; if (pla != null) { for (int i = 0; i < plane.length; i++) { if (plane[i] != null && plane[i].equals(pla)) { index = i; if (i != plane.length - 1) plane[i] = plane[i + 1]; else plane[i] = null; } if (i == index && plane[i + 1] == null) break; else if (i > index && i < plane.length - 1) { plane[i] = plane[i + 1]; if (i == plane.length - 1) plane[i] = null; } } ioo.write(plane); } pla = null; inputFrame.setVisible(false); plaInfo.setText(""); } else if (btn.getLabel().equals("Search")) { pla = null; if (!tf2[0].getText().equals("") || !tf2[1].getText().equals("")) { String condition = ""; if (!tf2[0].getText().equals("")) { condition = tf2[0].getText(); System.out.println(tf2[0].getText()); } else { condition = tf2[1].getText(); System.out.println(tf2[1].getText()); } for (int i = 0; i < plane.length; i++) { if (plane[i] != null) { System.out.println(plane[i].getFlightNumber()); if (plane[i].getFlightNumber().equals(condition) || plane[i].getStartCity() .equals(condition)) { System.out.println(plane[i].getFlightNumber()); pla = plane[i]; break; } } } } if (pla != null) { plaInfo.setText("FlightNumber: " + pla.getFlightNumber() + "\n" + "StartCity: " + pla.getStartCity() + "\n" + "Destination: " + pla.getDestination() + "\n" + "FlightTime: " + pla.getFlightTime() + "\n"); } searchFrame.setVisible(false); } else if (btn.getLabel().equals(" Exit ")) if (btn.getActionCommand().equals("input")) inputFrame.setVisible(false); else searchFrame.setVisible(false); } }} 老大 有包的情况下不是直接在 *.java 文件目录下编译的,javac 包名/*.java运行 java 包名.* class Plane implements Serializable { private String FlightNumber; private String StartCity; private String Destination; private String FlightTime; public Plane(String FlightNumber, String StartCity, String Destination, String FlightTime) { super(); this.StartCity = FlightNumber; this.StartCity = StartCity; this.Destination = Destination; this.FlightTime = FlightTime; } public Plane() { } public String getFlightNumber() { return FlightNumber; } public void setFlightNumber(String flightNumber) { this.FlightNumber = flightNumber; } public String getStartCity() { return StartCity; } public void setStartCity(String startCity) { this.StartCity = startCity; } public String getDestination() { return Destination; } public void setDestination(String destination) { this.Destination = destination; } public String getFlightTime() { return FlightTime; } public void setFlightTime(String flightTime) { this.FlightTime = flightTime; } public boolean equals(Object obj) { if (obj != null && (obj instanceof Plane)) if (this.getFlightNumber().equals(((Plane) obj).getFlightNumber()) && this.getStartCity().equals(((Plane) obj).getStartCity()) && this.getDestination().equals( ((Plane) obj).getDestination()) && this.getFlightTime().equals( ((Plane) obj).getFlightTime()) ) return true; return false; }} 第4个类class IOOperation { private File file = new File("C:\\info.txt"); public IOOperation() { try { if (!file.exists()) file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } /** * write to file */ public void write(Plane[] s) { try { FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream objOut = new ObjectOutputStream(fos); objOut.writeObject(s); objOut.close(); fos.close(); } catch (Exception e) { e.printStackTrace(); } } /** * read all student information from file */ public Plane[] getAllPlane() { Plane ss[] = new Plane[100]; try { if (file.length() > 0) { FileInputStream fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis); ss = (Plane[]) ois.readObject(); ois.close(); fis.close(); } } catch (Exception e) { e.printStackTrace(); } return ss; }} 要在 包的父目录下编译编译javac 包名/*.java 运行 java 包名.* 比如 a目录下 有个 test 目录test 目录有个Test.java ,Test.java中是 package test;那么编译就是在 a 目录下运行javac test/Test.java java test.Test 环境变量已经检查,应该没问题;path下是jdk的bin目录;classpath下是2楼的配置 我试过了没有问题包 planeInformation 每个类都要有 package planeInformation;比如 F:\workspace\planeInformation 这是我的目录结构java文件都在这下面F:\workspace>javac planeInformation/*.javaF:\workspace>java planeInformation.MainTestlz自己试试吧 你用javac时候,路径指向java文件的路径了吗?估计是这个问题。你看报的什么错误。然后再修修改。 java7的API中文版的 java皮肤 main方法传递参数问题 JDK5.0的主要新特征(1) 关于光驱的问题 初学者请教一程序 找两个东西,但是始终找不到. 请问:\u5C0F是一种什么编码格式? 怎样让客户端的线程阻塞, 在主机的服务线程小于最大数目以后再继续运行? eclipse jdk1.6.0_10安装后不能使用!!!!!!!!!!!!!本人是JAVA初学者 集合比较的问题
.;C:\Program Files\Java\jdk1.5\lib\tools.jar;C:\Program Files\Java\jdk1.5\lib\dt.jar;C:\Program Files\java\jdk1.5\jre\lib看看前面是不是少个 .; 配置
但是如果用个记事本,用原始的javac可以编译,但是无法运行。试了3台机器都有问题;
有兴趣的朋友可以弄去帮我看下。
package planeInformation;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class MainTest {
public static void main(String[] args) {
new PlaneInformation();
}
}
class PlaneInformation implements ActionListener {
Frame mainFrame;
Frame inputFrame;
Frame searchFrame;
TextArea plaInfo;
Label lb[] = new Label[4];
Label lb2[] = new Label[2];
TextField tf[] = new TextField[4];
TextField tf2[] = new TextField[2];
Button btn[] = new Button[3];
Button btn2[] = new Button[2];
Panel p1, p2, p3, p4;
IOOperation ioo;
Plane pla;
Plane plane[] = new Plane[100]; public PlaneInformation() {
/**
* 构造函数,初始话主窗口信息 set mainframe
*/
mainFrame = new Frame("PlaneInformation");
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// 菜单栏File选项添加
MenuItem item1 = new MenuItem("Record");
MenuItem item2 = new MenuItem("Search");
MenuItem item3 = new MenuItem("Modify");
MenuItem item4 = new MenuItem("Exit");
MenuItem item5 = new MenuItem("About");
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
item4.addActionListener(this);
item5.addActionListener(this);
Menu menu1 = new Menu("File");
menu1.add(item1);
menu1.add(item2);
menu1.add(item3);
menu1.addSeparator();
menu1.add(item4);
Menu menu2 = new Menu("Help");
menu2.add(item5);
MenuBar mb = new MenuBar();
mb.add(menu1);
mb.add(menu2);
mainFrame.setMenuBar(mb);
// 文本框控制区域设置
plaInfo = new TextArea();
plaInfo.setFont(new Font("serif", Font.PLAIN, 18));// 字体格式
mainFrame.add(plaInfo);
mainFrame.setSize(400, 250);// 大小
mainFrame.setLocation(200, 100);// 位置
mainFrame.setVisible(true);// 显示Frame
/**
* 记录飞机信息的窗口设置
*/
inputFrame = new Frame();
inputFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
inputFrame.setVisible(false);
}
});
p1 = new Panel(new GridLayout(4, 2));
p2 = new Panel();
String lbname[] = { "FlightNumber:", "StartCity:", "Destination:",
"FlightTime" };
String btnname[] = { "Save", "Delete", " Exit " };
// Record窗口中各字段名称、按钮设置
for (int i = 0; i < 4; i++) {
lb[i] = new Label(lbname[i]);
tf[i] = new TextField(15);
p1.add(lb[i]);
p1.add(tf[i]);
}
for (int i = 0; i < 3; i++) {
btn[i] = new Button(btnname[i]);
btn[i].addActionListener(this);
p2.add(btn[i]);
}
btn[2].setActionCommand("input");// **用来获取对象的标签或事先为这个对象设置的命令名**//
inputFrame.add(p1, BorderLayout.CENTER);
inputFrame.add(p2, BorderLayout.SOUTH);
inputFrame.pack();
inputFrame.setLocationRelativeTo(mainFrame);
/**
* set searchFrame which is used to search plane information
*/
searchFrame = new Frame("Search plane");
searchFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
searchFrame.setVisible(false);
}
});
p3 = new Panel(new GridLayout(2, 2));
p4 = new Panel();
String lbname2[] = { "FlightNumber :", "StartCity:" };
String btnname2[] = { "Search", " Exit " };
for (int i = 0; i < 2; i++) {
lb2[i] = new Label(lbname2[i]);
tf2[i] = new TextField(15);
p3.add(lb2[i]);
p3.add(tf2[i]);
}
for (int i = 0; i < 2; i++) {
btn2[i] = new Button(btnname2[i]);
btn2[i].addActionListener(this);
p4.add(btn2[i]);
}
btn2[1].setActionCommand("search");
searchFrame.add(p3, BorderLayout.CENTER);
searchFrame.add(p4, BorderLayout.SOUTH);
searchFrame.pack();
searchFrame.setLocationRelativeTo(mainFrame);
/**
* IO operation object
*/
ioo = new IOOperation();
plane = ioo.getAllPlane();
}
public void actionPerformed(ActionEvent e) {
/**
* 按钮功能实现
*/
if (e.getSource() instanceof MenuItem) {
MenuItem mi = (MenuItem) e.getSource();
if (mi.getLabel().equals("Record")) {// 如果点击Record
inputFrame.setTitle("Record");
inputFrame.setSize(200, 200);
for (int i = 0; i < 4; i++)
tf[i].setText("");
p2.remove(btn[1]);// 如果是记录信息,删除‘删除’按钮
btn[0].setActionCommand("input");// 按钮‘保存’功能实现
inputFrame.setVisible(true);
} else if (mi.getLabel().equals("Search")) {
searchFrame.setVisible(true);
} else if (mi.getLabel().equals("Modify")) {
inputFrame.setTitle("Modify");
if (pla != null) {// 修改信息时,文本框信息显示
tf[0].setText(pla.getFlightNumber());
tf[1].setText(pla.getStartCity());
tf[2].setText(pla.getDestination());
tf[3].setText(pla.getFlightTime());
}
p2.remove(btn[2]);
p2.add(btn[1]);
p2.add(btn[2]);
btn[0].setActionCommand("modify");
inputFrame.setVisible(true);
} else if (mi.getLabel().equals("Exit"))
System.exit(0);
else if (mi.getLabel().equals("About")) {
final Dialog progInfo = new Dialog(mainFrame, "ProgInfo", true);
progInfo.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
progInfo.dispose();
}
});
progInfo.setLayout(new FlowLayout());
Label l = new Label("Plane Information System");
progInfo.add(l);
progInfo.setSize(200, 80);
progInfo.setLocationRelativeTo(mainFrame);
progInfo.setVisible(true);
}
}
/**
* Button action
*/
else {
Button btn = (Button) e.getSource();
if (btn.getLabel().equals("Save")) {// 点击保存时,个文本框必须非空
if (!tf[0].getText().equals("") && !tf[1].getText().equals("")
&& !tf[2].getText().equals("")
&& !tf[3].getText().equals("")) {
Plane p = new Plane();
// Plane p = new Plane(tf[0].getText(), tf[1].getText(),
// tf[2]
// .getText(), tf[3].getText());
p.setFlightNumber(tf[0].getText());
p.setStartCity(tf[1].getText());
p.setDestination(tf[2].getText());
p.setFlightTime(tf[3].getText());
System.out.println(p.getFlightNumber());
if (btn.getActionCommand().equals("input")) {
for (int i = 0; i < plane.length; i++) {
if (plane[i] == null) {
plane[i] = p;
System.out.println(p.getFlightNumber());
break;
}
}
ioo.write(plane);
} else {
for (int i = 0; i < plane.length; i++) {
if (plane[i].equals(pla)) {
plane[i] = p;
break;
}
}
ioo.write(plane);
}
}
inputFrame.setVisible(false);
plaInfo.setText("");
} else if (btn.getLabel().equals("Delete")) {
int index = 200;
if (pla != null) {
for (int i = 0; i < plane.length; i++) {
if (plane[i] != null && plane[i].equals(pla)) {
index = i;
if (i != plane.length - 1)
plane[i] = plane[i + 1];
else
plane[i] = null;
}
if (i == index && plane[i + 1] == null)
break;
else if (i > index && i < plane.length - 1) {
plane[i] = plane[i + 1];
if (i == plane.length - 1)
plane[i] = null;
}
}
ioo.write(plane);
}
pla = null;
inputFrame.setVisible(false);
plaInfo.setText("");
} else if (btn.getLabel().equals("Search")) {
pla = null;
if (!tf2[0].getText().equals("")
|| !tf2[1].getText().equals("")) {
String condition = "";
if (!tf2[0].getText().equals("")) {
condition = tf2[0].getText();
System.out.println(tf2[0].getText());
} else { condition = tf2[1].getText();
System.out.println(tf2[1].getText());
}
for (int i = 0; i < plane.length; i++) {
if (plane[i] != null) {
System.out.println(plane[i].getFlightNumber());
if (plane[i].getFlightNumber().equals(condition)
|| plane[i].getStartCity()
.equals(condition)) {
System.out.println(plane[i].getFlightNumber());
pla = plane[i];
break;
}
}
}
}
if (pla != null) {
plaInfo.setText("FlightNumber: " + pla.getFlightNumber()
+ "\n" + "StartCity: " + pla.getStartCity() + "\n"
+ "Destination: " + pla.getDestination() + "\n"
+ "FlightTime: " + pla.getFlightTime() + "\n");
}
searchFrame.setVisible(false);
} else if (btn.getLabel().equals(" Exit "))
if (btn.getActionCommand().equals("input"))
inputFrame.setVisible(false);
else
searchFrame.setVisible(false);
}
}
}
javac 包名/*.java
运行 java 包名.*
private String FlightNumber;
private String StartCity;
private String Destination;
private String FlightTime; public Plane(String FlightNumber, String StartCity, String Destination,
String FlightTime) {
super();
this.StartCity = FlightNumber;
this.StartCity = StartCity;
this.Destination = Destination;
this.FlightTime = FlightTime; } public Plane() {
} public String getFlightNumber() {
return FlightNumber;
} public void setFlightNumber(String flightNumber) {
this.FlightNumber = flightNumber;
} public String getStartCity() {
return StartCity;
} public void setStartCity(String startCity) {
this.StartCity = startCity;
} public String getDestination() {
return Destination;
} public void setDestination(String destination) {
this.Destination = destination;
} public String getFlightTime() {
return FlightTime;
} public void setFlightTime(String flightTime) {
this.FlightTime = flightTime;
} public boolean equals(Object obj) {
if (obj != null && (obj instanceof Plane))
if (this.getFlightNumber().equals(((Plane) obj).getFlightNumber())
&& this.getStartCity().equals(((Plane) obj).getStartCity())
&& this.getDestination().equals(
((Plane) obj).getDestination())
&& this.getFlightTime().equals(
((Plane) obj).getFlightTime()) )
return true;
return false;
}
}
private File file = new File("C:\\info.txt"); public IOOperation() {
try {
if (!file.exists())
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
} /**
* write to file
*/
public void write(Plane[] s) {
try {
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream objOut = new ObjectOutputStream(fos);
objOut.writeObject(s);
objOut.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
} /**
* read all student information from file
*/
public Plane[] getAllPlane() {
Plane ss[] = new Plane[100];
try {
if (file.length() > 0) {
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
ss = (Plane[]) ois.readObject();
ois.close();
fis.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return ss;
}
}
编译javac 包名/*.java
运行 java 包名.* 比如 a目录下 有个 test 目录test 目录有个Test.java ,Test.java中是 package test;那么编译就是在 a 目录下运行
javac test/Test.java java test.Test
path下是jdk的bin目录;
classpath下是2楼的配置
F:\workspace>javac planeInformation/*.javaF:\workspace>java planeInformation.MainTestlz自己试试吧
你看报的什么错误。然后再修修改。