简体   繁体   English

线程“main”中的异常 java.lang.ClassCastException:类 com.sun.proxy.$Proxy0 不能转换为类船员

[英]Exception in thread “main” java.lang.ClassCastException: class com.sun.proxy.$Proxy0 cannot be cast to class crewcut

As per stated in the title, as I were to continue to next supposed section in the coding.正如标题中所述,因为我将继续进行编码中的下一个假设部分。 The RMI system did not the display the action based on my input. RMI 系统没有根据我的输入显示操作。 I want it to display the next part of the coding when the system recognized the input as Customer / Barbershop.当系统将输入识别为客户/理发店时,我希望它显示编码的下一部分。

How do i make it show the next case statement?我如何让它显示下一个案例陈述?

Client客户

import java.rmi.*;
import java.net.*;
import java.io.*;
import java.util.*;

public class crewcut_client {

public static void main(String[] args) {


    try{
        Scanner sc = new Scanner(System.in);

        System.out.println("Welcome to CrewCut Service");
        System.out.println("Are you a 'CUSTOMER' | 'BARBER' ? Type in below");
        String resp = sc.next();

        crewcut cc = (crewcut) Naming.lookup("rmi://localhost/CrewCut");
        switch (resp){
            case "CUSTOMER":
            case "customer":
            case "Customer":
            {
                System.out.println("Hello Customer !");
                System.out.println("Welcome to our system");
                System.out.println("Please enter your name :");
                String name = sc.nextLine();
                System.out.println("Please enter your contact num :");
                String num = sc.next();
                System.out.println("Here are our services :");
                System.out.println("Hair Cut RM15");
                System.out.println("Hair Wash RM20");
                System.out.println("Hair Dye RM25");
                System.out.println("Press '1' for Hair Cut");
                System.out.println("Press '2' for Hair Wash");
                System.out.println("Press '3' for Hair Dye");
                String service = sc.next();
                System.out.println("Your day of booking ? Monday | Tuesday | Wednesday | Thursday | Friday |Saturday | Sunday");
                String day = sc.next();
                //impl code
                System.out.println(cc.check_client(name,num,service,day));
            break;
            }
            case "BARBER":
            case "barber":
            case "Barber":
            {
                System.out.println("Hello Barber !");
                System.out.println("Are you in for work today? Enter 'Y' for YES or 'N' for NO" );
                String attend = sc.nextLine();
                if (attend.equals("Y")){
                    System.out.println("Welcome to work ! ");
                    System.out.println("The shop shall be closed in 9pm");
                }else if (attend.equals("N")){
                    System.out.println("Hope to see you soon !");
                }else{
                    System.out.println("Invalid input");
                }
            }
        }
    }catch (RemoteException re){
        re.printStackTrace();
    }catch (NotBoundException nbe){
        nbe.printStackTrace();
    }catch(MalformedURLException mfe){
        mfe.printStackTrace();
    }
}}

Server服务器

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;

public class crewcut_server {
public static void main(String[] args) {
    try{
        crewcutimpl ccl = new crewcutimpl();
        Naming.rebind("rmi://localhost/CrewCut",ccl);
    }catch (RemoteException re){
        re.printStackTrace();
    }catch (MalformedURLException mfe){
        mfe.printStackTrace();
    }
}
}

Implementation执行

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.util.Scanner;

public class crewcutimpl extends UnicastRemoteObject implements crewcut{
public  crewcutimpl() throws RemoteException{
    super();
}
public String check_client (String name, String num, String service, String day){
    String display;
    int price = 0;
    switch (service){
        case "1":
            price = 15;
            break;
        case "2" :
            price = 20;
            break;
        case "3":
            price = 25;
            break;
    }display =" Your booking has been entered into the system Mr/Mrs " + name + "\n We shall contact 
     you through this num : " + num + "\n Service wanted : "+ service + "Total price :" + price +"Day 
     of appointment :" + day;
    return display;

    }
    }

Interface界面

import java.rmi.RemoteException;

 public interface crewcut {

public String check_client(String name, String num, String service, String day) throws 
RemoteException;
}

接口必须具有“扩展远程”,应该可以解决您的第二个问题“线程“main”中的异常 java.lang.ClassCastException: class com.sun.proxy.$Proxy0 cannot be cast to class...”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java:java.lang.ClassCastException:com.sun.proxy.$Proxy0 类无法转换为 com.sun.tools.javac.processing.JavacProcessingEnvironment 类 - java: java.lang.ClassCastException: class com.sun.proxy.$Proxy0 cannot be cast to class com.sun.tools.javac.processing.JavacProcessingEnvironment java.lang.ClassCastException: com.sun.proxy.$Proxy0 不能转换为 org.andrea.myexample.myDeclarativeTransactionSpring.StudentJDBCTemplate - java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to org.andrea.myexample.myDeclarativeTransactionSpring.StudentJDBCTemplate java.lang.ClassCastException:com.sun.proxy。$ Proxy47无法转换为 - java.lang.ClassCastException: com.sun.proxy.$Proxy47 cannot be cast to RMI:java.lang.ClassCastException:com.sun.proxy。$ Proxy1无法转换为Funktion - RMI: java.lang.ClassCastException: com.sun.proxy.$Proxy1 cannot be cast to Funktion java.lang.ClassCastException:com.sun.proxy。$ Proxy1无法转换为 - java.lang.ClassCastException: com.sun.proxy.$Proxy1 cannot be cast to java.lang.ClassCastException:com.sun.proxy。$ Proxy29无法转换为com.frodo.questionbank.service.impl.QuestionService - java.lang.ClassCastException: com.sun.proxy.$Proxy29 cannot be cast to com.frodo.questionbank.service.impl.QuestionService ClassCastException:com.sun.proxy.$ProxyX 无法转换为类 - ClassCastException: com.sun.proxy.$ProxyX cannot be cast to a class java.lang.ClassCastException: com.sun.proxy.$Proxy8 不能转换为 org.openqa.selenium.internal.WrapsDriver - java.lang.ClassCastException: com.sun.proxy.$Proxy8 cannot be cast to org.openqa.selenium.internal.WrapsDriver 原因:java.lang.ClassCastException:com.sun.proxy.$Proxy67 无法转换为 org.omg.CORBA.Z497031794414A552435F90151BZAC3 - Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy67 cannot be cast to org.omg.CORBA.Object java.lang.ClassCastException:com.sun.proxy。$ Proxy219无法转换为org.springframework.data.redis.connection.StringRedisConnection - java.lang.ClassCastException: com.sun.proxy.$Proxy219 cannot be cast to org.springframework.data.redis.connection.StringRedisConnection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM