如何使用终端运行依赖于另一个类的类

时间:2020-06-19 16:48:54

标签: java libraries

我有两个班:Ristorante和Ristoratori。两者都使用外部库进行thr I / O。这两个类已经编译,但是当Ristoratori(引用Ristorante)启动并询问我读取文件的路径时,会出现一些错误。

Ristorante:

 public class Ristorante implements Serializable {
    static ConsoleInputManager in = new ConsoleInputManager();
    static ConsoleOutputManager out = new ConsoleOutputManager();
    private static final long serialVersionUID = 7613409875169727612L;
    String nome ;
    String via ;
    String nciv ;
    String città ;
    String prov ;
    String CAP ;
    String ntel ;
    String web ;
    String tipris ;
    ArrayList<String> listagiud = new ArrayList<String>() ;



    public Ristorante(String nome,String via, String nciv,String città, String prov,String CAP, String ntel,String tipris, String web) {
        this.nome = nome;
        this.via = via;
        this.nciv= nciv;
        this.città = città;
        this.prov = prov;
        this.CAP = CAP;
        this.ntel = ntel;
        this.tipris = tipris;
        this.web = web;
    }

    public void addGiud(String giud) {
        listagiud.add(giud);
    }

    public ArrayList<String> getCommenti() {
        out.println(listagiud);
        return this.listagiud;
    }

    public String getNome() {
        return this.nome;
    }

    public String getTipris() {
        return this.tipris;
    }

    public String getInfo() {
        String info = "Nome : " + this.nome + " , Via : " + this.nciv + " , Città : " + this.città + " " + this.CAP + 
        " ,  Provincia : " + this.prov + " , Numero di telefono : " + this.ntel + " , Cucina del ristorante : " + this.tipris + " , Sito web : " + this.web + " , Commenti dagli utenti : " + this.listagiud.toString();
        out.println(info);
        return info;
    }
public static void main(String[] args){
System.out.println("ris partito");
}
}

Ristoratori:

 public class Ristoratori {
        static ConsoleInputManager in = new ConsoleInputManager();
        static ConsoleOutputManager out = new ConsoleOutputManager();
        static HashMap<String,ArrayList<String>> map = new HashMap<String,ArrayList<String>>();
        static String path2;
        static File EatAd;
        static String selnome = "";
        static ArrayList<Ristorante> listaris = new ArrayList<Ristorante>();



    public static void putRistorante (ArrayList<Ristorante> listaris) {
        String nome = in.readLine("Inserire nome ristorante ");
        String via = (in.readLine("Inserire via del ristorante "));
        String nciv =(in.readLine("Inserire n° civ del ristorante "));
        String città =(in.readLine("Inserire città del ristorante "));
        String prov =(in.readLine("Inserire sigla provincia del ristorante "));
        String CAP =(in.readLine("Inserire CAP del ristorante "));
        String ntel =(in.readLine("Inserire n° telefono del ristorante "));
        String web =(in.readLine("Inserire sito web del ristorante "));
        String tipris =(in.readLine("Inserire tipologia di cucina del ristorante(italiano-fusion-ecc) "));
        Ristorante r= new Ristorante(nome, via, nciv, città, prov, CAP, ntel, tipris ,web);
        listaris.add(r);
        listaris.forEach(k -> k.getInfo());
        }

    @SuppressWarnings("unchecked")
    public static ArrayList<Ristorante> readDati (File EatAd) throws IOException, ClassNotFoundException {
        ObjectInputStream is = new ObjectInputStream(new FileInputStream(EatAd));
        listaris = (ArrayList<Ristorante>) is.readObject();
        is.close();
        return listaris;
    }

    public static void writeDati (File EatAd, ArrayList<Ristorante> listaris ) throws IOException {
        ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(EatAd));
        os.writeObject(listaris);
        os.close();
        }


    public static void main(String[] args) throws IOException, ClassNotFoundException {
        path2 = in.readLine("Indicare percorso della cartella");
        path2 += "\\EatAdvisor.dati";
        EatAd = new File(path2);
        if (EatAd.exists() == false) {
            EatAd.createNewFile();
            out.println("File da creare !");
        }
        else {
            readDati(EatAd);
            out.println("File trovato !");
        }

        while (in.readSiNo("Inserire ristorante ? ")) {
            putRistorante(listaris);
        }
        writeDati(EatAd, listaris);

        out.println("File aggiornato \n" + "Chiusura applicazione ! ");
        } 
    }

这是终端,请帮助我,因为我找不到解决此问题的方法,因为当我从Eclipse开始时,一切都很好:

  C:\Users\Alecs\Desktop\EsamelabA\src\ristoratori>java -cp .;C:\Users\Alecs\Desktop\EsamelabA\libreria\prog-4ed.jar Ristoratori
    Indicare percorso della cartellaC:\\Users\\Alecs\\Desktop\\EsamelabA\\data
    Exception in thread "main" java.lang.ClassNotFoundException: ristoratori.Ristorante
            at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
            at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
            at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
            at java.base/java.lang.Class.forName0(Native Method)
            at java.base/java.lang.Class.forName(Class.java:427)
            at java.base/java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:762)
            at java.base/java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1982)
            at java.base/java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1868)
            at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2161)
            at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1685)
            at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:499)
            at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:457)
            at java.base/java.util.ArrayList.readObject(ArrayList.java:898)
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.base/java.lang.reflect.Method.invoke(Method.java:564)
            at java.base/java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1216)
            at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2359)
            at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2193)
            at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1685)
            at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:499)
            at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:457)
            at Ristoratori.readDati(Ristoratori.java:61)
            at Ristoratori.main(Ristoratori.java:98)

0 个答案:

没有答案