Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.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
Netbeans 在二进制文件中搜索和显示时显示错误_Netbeans - Fatal编程技术网

Netbeans 在二进制文件中搜索和显示时显示错误

Netbeans 在二进制文件中搜索和显示时显示错误,netbeans,Netbeans,我是一名高中生,我不太擅长编程。我对这个方法有一个问题,它打算显示保存在文件中的某个客户机的数据。当我运行程序并在界面上测试它时,文本字段只显示“Error en el archivo”,我不明白为什么。有人能帮我吗 public void buscarclientes() throws IOException{ try{ RandomAccessFile archivoclientes=new RandomAccessFile ("clientesinf.dat", "rw")

我是一名高中生,我不太擅长编程。我对这个方法有一个问题,它打算显示保存在文件中的某个客户机的数据。当我运行程序并在界面上测试它时,文本字段只显示“Error en el archivo”,我不明白为什么。有人能帮我吗

public void buscarclientes() throws IOException{
    try{
    RandomAccessFile archivoclientes=new RandomAccessFile ("clientesinf.dat", "rw");
    String nom =""; boolean existenombre=false; String nombre = ""; String email = ""; int tel=0; int cliente=0; long cantidadclientes=0; long tamclientes=94;
    cantidadclientes=archivoclientes.length()/tamclientes;
    nombre=this.Bclientes.getText();
    nombre=nombre.trim();

    while ((existenombre==false)&&(cliente<cantidadclientes)){
        archivoclientes.seek(cliente*tamclientes);


        for (int n=1; 1<=20;n++)
            nom=nom+Character.toString(archivoclientes.readChar());
            nom=nom.trim();

            if (nom.equalsIgnoreCase(nombre)){
            for (int n=1; 1<=30;n++)
            email=email+Character.toString(archivoclientes.readChar());
            email=email.trim();
            tel=archivoclientes.readInt();

           Mostrardatos.setText("Nombre:" +  nom + "\nEmail:" + email + "\nTeléfono:" + tel) ;

        existenombre=true;
        }
        nom="";
        cliente=cliente++;
    if (existenombre==false);
    {
        Mostrardatos.setText("No se encontró el nombre");

    archivoclientes.close();
    }}}
    catch (EOFException e){}       
    {
        Mostrardatos.setText("Error en el archivo");
    }

}
public void buscarclientes()引发IOException{
试一试{
RandomAccessFile ArchivoClient=新的RandomAccessFile(“clientsinf.dat”、“rw”);
String nom=“”;boolean existenombre=false;String nombre=“”;String email=“”;int tel=0;int cliente=0;long cantidadclientes=0;long tamclientes=94;
cantidadclientes=archivoclients.length()/tamclientes;
nombre=this.bclients.getText();
nombre=nombre.trim();
而((existenombre==false)&&(cliente文本字段显示“Error en el archivo”,因为它正在运行这行代码:

Mostrardatos.setText("Error en el archivo");
看起来好像有人想把这个放进捕鼠器里

catch (EOFException e){} 
但是,通过将最后一个“{}”放在末尾关闭catch块,使文本 将始终在末尾设置,无论存在哪些错误

我的猜测是将其改为:

} catch (EOFException e) {
    e.printStackTrace();
    Mostrardatos.setText("Error en el archivo");
}
然后,如果它仍然设置错误,您应该在Netbeans的输出窗口中获得更详细的信息

如果使用
ALT-SHIFT-F
对代码进行格式化,您的代码可能会更容易阅读