如果这些类都写在一个文本里的话,该文本命名只能是public修饰的类名,且只能有一个类被public修饰,其他类去掉public,或者是以包含main()方法的类名为文件名。
该程序中,除了Life类外,其他的类把public去掉,并把文件名改成Life.java,然后编译javac Life.java,运行java Life
Ⅱ 编译怎么老是提示我找不到符号,到底是哪里出错了啊 求大神看看
你的写法
for(int x=0; x<拿耐arr.length; x++);
{
if (arr[x] == key)
return x;
}
for这行后面有分号,表示消芹春for语句包括循环体均在此结束,后面大括号是另外一个语句了
而for语句中x变量是临时申请的,仅在for语句中有效,因此得到编译错误
解决方法:
将首慎for(int x=0; x<arr.length; x++);
改成for(int x=0; x<arr.length; x++)
Ⅲ java编译提示找不到符号
修改后如下:
代码稿虚凯具誉知体位置添加了注释,请花点时间看一看,理解更透彻一点
public static void main(String[] args) {
// 变量定义,需要再代码块之外,嵌套代码块中才是可见的
Socket clientSocket = null;
DataOutputStream outbound = null;
DataInputStream inbound = null;
InputStreamReader inS = null;
try {
// 与服务器建立连接
clientSocket = new Socket("192.100.100.43", 82);
System.out.println("Client1: " + clientSocket);
// 初始化流键唤对象
outbound = new DataOutputStream(clientSocket.getOutputStream());
inbound = new DataInputStream(clientSocket.getInputStream());
inS = new InputStreamReader(inbound);
// 发送数据
outbound.writeBytes("hello\r\n");
System.out.println("hello");
outbound.flush();
int c;
while ((c = inS.read()) != -1) {
System.out.print((char) c);
}
} catch (UnknownHostException uhe) {
System.out.println("UnknownHostException: " + uhe);
} catch (IOException ioe) {
System.err.println("IOException: " + ioe);
} finally {
// 此处需要逐个try catch,避免其中一个出问题后,后面的流都不关闭
try {
if (null != inS) {
inS.close();
// 为对象赋null,表示该对象已不存在任何引用关系,可使垃圾回收更及时
inS = null;
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (null != outbound) {
outbound.close();
outbound = null;
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (null != inbound) {
inbound.close();
inbound = null;
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (null != clientSocket) {
clientSocket.close();
clientSocket = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Ⅳ java编译报错 : 找不到符号
StringHelper没有import进来 你自己要找一下你的岩猜stringhelper在哪个包里面。这个不是公共包裤枣虚,胡燃别人肯定不知道。
Ⅳ java编译时提示错误:找不到符号
public class clock
{
public static void main(String args[])
{
ClockView cv = new ClockView();
cv.setVisible(true);//这里setVisible错了
try {
for (;;) {
cv.refreshTimeDisply();//这里refreshTimeDisply错了
Thread.sleep(500);
}
} catch (Exception e)
{
System.out.println("Error:" + e);
}
}
}
class ClockView extends javax.swing.JFrame
{
private javax.swing.JLabel tLabel = new javax.swing.JLabel();
ClockView()
{
this
.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
this.setSize(95, 45);
this.getContentPane().add(tLabel);
this.refreshTimeDisply(); //这个单词错了
}
protected String getDigitsAsString(int i)
{
String str = Integer.toString(i);
if (i < 10)
str = "0" + str;
return str;
}
public void refreshTimeDisply() {
Timestamp t = new Timestamp();
t.fillTimes();
String display = getDigitsAsString(t.hrs) + ":"
+ getDigitsAsString(t.mins) + ":"
+ getDigitsAsString(t.secs); // 这个getDigitsAsString写错了
tLabel.setText("扰举 " + display);
tLabel.repaint();
}
}
class Timestamp
{
int hrs, mins, secs;
void fillTimes() {
java.util.Calendar now ; //这察或个Calendar 错了
now = java.util.Calendar.getInstance() ;
hrs = now.get(java.util.Calendar.HOUR_OF_DAY);
mins = now.get(java.util.Calendar.MINUTE);
secs = now.get(java.util.Calendar.SECOND);
}
}
主要就是几个方法的单败李伍词写错了
Ⅵ Java编译错误:找不到符号
说明代码中有中文字符,或者是括号不是对称的导致的,可以参考下以下入门代码:
// 一个文件中只能有一个共有的类,并且与文件名称一致,大小写注意
public class HelloWorld{
// 程序的入口
public static void main(String args[]){
// 向控制台输出信息
System.out.println("欢迎java01班的同学");
}
}
Ⅶ JAVA编译时找不到符号
Lable -> Label
ture -> true
Double.pareDoublet1 -》 Double.parseDouble (t1.getText())
actionperformed -》actionPerformed
完整如下
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class round extends Frame implements ActionListener {
TextField t1, t2, t3, t4;
Button b1;
public round() {
setLayout(new FlowLayout());
t1 = new TextField(20);
t2 = new TextField(20);
t3 = new TextField(20);
t4 = new TextField(20);
b1 = new Button("计算");
add(new Label("输入圆的含碧半渣培径:"));
add(t1);
add(new Label("得出圆的直径:"));
add(t2);
add(new Label("得出圆的面积:"));
add(t3);
add(new Label("得出圆的如老唯周长:"));
add(t4);
add(b1);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b1.addActionListener(this);
setVisible(true);
setBounds(400, 400, 440, 400);
validate();
}
public void actionPerformed(ActionEvent e) {
double temp, r, a, c;
temp = Double.parseDouble(t1.getText());
r = 2 * temp;
a = 3.14 * temp * temp;
c = 2 * 3.14 * temp;
t2.setText(String.valueOf(r));
t3.setText(String.valueOf(r));
t4.setText(String.valueOf(r));
}
public static void main(String args[]) {
new round();
}
}
Ⅷ java编译程序的时候总是提示找不到符号
public static void main(String[] args) throws Exception {
System.out.println("请输入你的姓名:");
Scanner in = new Scanner(System.in);
String lk = in.next();
System.out.println("请输入你的年龄:");
int kj = in.nextInt();
System.out.println("姓名:" + lk);
System.out.println("年龄:" + kj);
}
Ⅸ 编译时 说找不到符号
this.setBound(100,200.400,300);
楼上的大神们,真正的问题是桐洞在这里.
根据提示:
6:找不到符号
符号: 方法 setBound(int.double.int)
位置: 类 myFrame
this.setBound(100,200,400,300)
^
很明显是 setBound()出错了/.. 错误就在于LZ把逗号","笑轮慎写成了点"."
setBound(int,int,int,int).变成了setBound(int,double,int).. 故而报错碰敬.