如果這些類都寫在一個文本里的話,該文本命名只能是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).. 故而報錯碰敬.