mardi 4 avril 2017

updated Intellij gives me some compile errors using Reflection

Vector vec = new Vector(20);
            System.out.println("Enter your name please");
            Scanner scanner = new Scanner(System.in);
            PlayerThread player = new PlayerThread(scanner.nextLine());
            int j = 0;
            Bot botobj;
            System.out.println("Hi " + player.name);
            for (int y = 0; y < 2; y++) {
                System.out.println("Enter the name of the Bot & File with space between them");
                String botname = scanner.nextLine();
                String[] temp = botname.split("\\s+");
                Class reflectClass = null;
                try {
                    reflectClass = Class.forName("Chat_bot.Bot");
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                Class[] carg = new Class[2];
                for (int i = 0; i < carg.length; i++)
                    carg[i] = String.class;
                try {
                    Constructor ct = reflectClass.getConstructor(carg);
                    try {
                        botobj = (Bot) ct.newInstance(temp);
                        vec.addElement(botobj);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                } catch (NoSuchMethodException e1) {
                    e1.printStackTrace();
                }
            }

Hi I have updated my Intellij Idea recently & the code which was being compiled with no problem before, is getting compile error with this version.... what can I replace here to new an object from a class named "Bot" using Reflection now? please help me with this :) The error is in line: botobj = (Bot) ct.newInstance(temp);





Aucun commentaire:

Enregistrer un commentaire