Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Eclipse希望在已经存在分号的位置使用分号_Java_Eclipse_Syntax - Fatal编程技术网

Java Eclipse希望在已经存在分号的位置使用分号

Java Eclipse希望在已经存在分号的位置使用分号,java,eclipse,syntax,Java,Eclipse,Syntax,我正在使用Eclipse完成一项大学作业,仍在学习如何编写代码,因此请忽略附件中的劣质工作!我已经为文件处理创建了一个类,最奇怪的事情发生了,Eclipse告诉我应该在已经存在分号的地方使用分号。我根本看不出问题是什么,对班上的其他同学进行了注释,看看这是否有什么不同,但问题仍然存在 错误出现在行ObjectOutputStream superObjectOutputStream上 这是我的密码: package filehandling; import java.io.File; impor

我正在使用Eclipse完成一项大学作业,仍在学习如何编写代码,因此请忽略附件中的劣质工作!我已经为文件处理创建了一个类,最奇怪的事情发生了,Eclipse告诉我应该在已经存在分号的地方使用分号。我根本看不出问题是什么,对班上的其他同学进行了注释,看看这是否有什么不同,但问题仍然存在

错误出现在行
ObjectOutputStream superObjectOutputStream上

这是我的密码:

package filehandling;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;

import javax.swing.JOptionPane; 

public class SuperstarFile {

File superFile;
FileInputStream superFileInputStream;
FileOutputStream superFileOutputStream;
ObjectInputStream superObjectInputStream;
ObjectOutputStream superObjectOutputStream; 


superFile = new File("superstars.data");
/*
public void saveFile (ArrayList maleWrestler)
{
    try
    {
        superFileOutputStream = new FileOutputStream(superFile);
        superObjectOutputStream = new ObjectOutputStream(superFileOutputStream);
        superObjectOutputStream.writeObject(maleWrestler);
        superObjectOutputStream.close();
        superFileOutputStream.close();

    }
    catch(final Exception e){
        JOptionPane.showMessageDialog(null, "Ooops -  " +e);
    }

}


public ArrayList readFile(ArrayList goingIn)
{
    ArrayList temp;


    try{
        superFileInputStream = new FileInputStream(superFile);
        superObjectInputStream = new ObjectInputStream(superFileInputStream);
        temp = (ArrayList) superObjectInputStream.readObject();
        superObjectInputStream.close();
        superFileInputStream.close();
    }
    catch(Exception e){
        JOptionPane.showMessageDialog(null, "Ooops - " +e);
    }
    return temp;
}

*/
}

将值赋给实例字段时,没有花括号,也没有方法体或构造函数围绕赋值

更改:

superFile = new File("superstars.data");
致:

。。。对于实例块

否则,将赋值放在构造函数中:

SuperstarFile() {
    superFile = new File("superstars.data");
}
您还可以使用实例方法:

void doSomething() {
    superFile = new File("superstars.data");
}
或者,如其他地方所述,您可以直接在声明中指定字段:

File superFile = new File("superstars.data");

将值赋给实例字段时,没有花括号,也没有方法体或构造函数围绕赋值

更改:

superFile = new File("superstars.data");
致:

。。。对于实例块

否则,将赋值放在构造函数中:

SuperstarFile() {
    superFile = new File("superstars.data");
}
您还可以使用实例方法:

void doSomething() {
    superFile = new File("superstars.data");
}
或者,如其他地方所述,您可以直接在声明中指定字段:

File superFile = new File("superstars.data");

你的问题不在于“;”但后面还有任务。更改代码如下:

public class SuperstarFile {

    FileInputStream superFileInputStream;
    FileOutputStream superFileOutputStream;
    ObjectInputStream superObjectInputStream;
    ObjectOutputStream superObjectOutputStream;

    File superFile = new File("superstars.data");
...
}
并且不会给出错误消息。

但是,要做一些真正的工作,你的文件应该有方法。

你的问题不在于“;”但后面还有任务。更改代码如下:

public class SuperstarFile {

    FileInputStream superFileInputStream;
    FileOutputStream superFileOutputStream;
    ObjectInputStream superObjectInputStream;
    ObjectOutputStream superObjectOutputStream;

    File superFile = new File("superstars.data");
...
}
并且不会给出错误消息。

但要想做一些真正的工作,你的文件应该有方法。

@Thori很高兴听到:)@Thori很高兴听到:)