Below is the switch statement for reference but if narrowed it down to coming from the calls to s.next()
After some digging ive found that this error normally comes from using something from too low a language level (below 7)
Is that the issue in this case? If so how do I work around not being able to use scanner.next?? (also in other classes also scanned by Reflections scanner.next() seems to work, its ONLY scanner in this class ONLY giving me some issues)
Code of SLR class:
Scanner s = new Scanner(System.in);
switch (**s.next()**) {
case ("m"):{
System.out.println("Enter minutes");
e = s.nextInt() * 60;
System.out.println("TO " + (e / 60) + " minutes");
break;
}
//some code
}
The reflections code: (the above class is contained in clivet268.Operations package)
Reflections reflections = new Reflections("clivet268.Operations");
Set<Class<? extends Operation>> opstoinit = new HashSet<>(reflections.getSubTypesOf(Operation.class));
opstoinit.forEach((e) -> {
try {
e.getDeclaredConstructor().newInstance().init();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException ex) {
throw new RuntimeException(ex);
}
});
The 3 errors given:
Exception in thread "main" java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.RuntimeException: could not create class file from SLR.class
at org.reflections.Reflections.scan(Reflections.java:166)
at org.reflections.Reflections.<init>(Reflections.java:91)
at org.reflections.Reflections.<init>(Reflections.java:99)
at clivet268.Enforcry.initOperations(Enforcry.java:37)
at clivet268.Enforcry.main(Enforcry.java:20)
Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: could not create class file from SLR.class
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: could not create class file from SLR.class
at org.reflections.Reflections.scan(Reflections.java:162)
... 4 more
Caused by: java.lang.RuntimeException: could not create class file from SLR.class
Caused by: java.lang.RuntimeException: could not create class file from SLR.class
at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:41)
at org.reflections.Reflections$2.run(Reflections.java:149)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.io.IOException: invalid constant type: 18
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1023)
at javassist.bytecode.ConstPool.read(ConstPool.java:966)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:127)
at javassist.bytecode.ClassFile.read(ClassFile.java:693)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:85)
at org.reflections.adapters.JavassistAdapter.createClassObject(JavassistAdapter.java:86)
at org.reflections.adapters.JavassistAdapter.createClassObject(JavassistAdapter.java:22)
at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:38)
... 6 more
Caused by: java.io.IOException: invalid constant type: 18
Ive found the answer!
Update your javassist class, I chose to do so through my build.gradle class using this line
implementation 'org.javassist:javassist:3.29.0-GA'
If there is a new version by the time of reading this replace "29.0" with the latest version number