-3

I am getting an error as "The package java.util is accessible from more than one module: error" while importing file in java.

  • 3
    We need more details about what you are exactly doing – D. Lawrence Nov 26 '19 at 14:24
  • Here is my code and the error message. I hope this helps. Thank you Lawrence for your quick response. package Volume2; import java.util.Scanner; public class ImpScanner { public static void main(String[] args) { Scanner InputNum = new Scanner(System.in); int intScanner; int i; System.out.println("Enter a valid number from 0 to 99 and hit enter:"); intScanner = InputNum.nextInt(); for(i =1; i<=5; i++) { if((intScanner >= 0) && (intScanner <= 99)) System.out.println("Your entered number is: " +intScanner); } } } – Sujan Shrestha Nov 26 '19 at 14:31
  • Exception in thread "main" java.lang.Error: Unresolved compilation problems: Cannot instantiate the type Scanner The method nextInt() is undefined for the type Scanner at Volume2.ImpScanner.main(ImpScanner.java:9) – Sujan Shrestha Nov 26 '19 at 14:32
  • 1
    Your problem is not the code. Your problem most likely are compile time dependencies. How do you compile / run your program? Are you using an IDE? Which Java Version do you use? Please give us more detail! – Jochen Reinhardt Nov 26 '19 at 14:38

1 Answers1

2

It seems like you messed things up in your module path. The error message indicates that you depend on multiple java modules that all export the java package java.util.

This is also called split package, as some classes in this package might be loaded from one module the others from another module.

With the new Java module system introduced with Java 9 this is strictly forbidden.

java.util should only be present in java.base module and nowhere else.

If you need further information, please tell us how you built and try to run your application.

Jochen Reinhardt
  • 833
  • 5
  • 14
  • I am still confused. Sorry! Can please illustrate little more. Thanks! – Sujan Shrestha Nov 26 '19 at 14:39
  • If I had to guess, I would say, you included two JRE instances both prodviding the `java.base` module and thus exporting the `java.util` package. This is not allowed. The `java.tutil` package can only be loaded from a single module. It is not allowed to split a java package across multiple java modules. But this seems to be your error. See here for further details: https://blog.codefx.org/java/java-9-migration-guide/#Split-Packages – Jochen Reinhardt Nov 26 '19 at 15:09
  • That was very helpful, thank you! I was able to solve the problem. – Sujan Shrestha Nov 26 '19 at 16:47