When using class.getResource() to retrieve a specific resource file, you may encounter unexpected null results. This article explores potential reasons behind this issue and provides an alternate solution.
The line of code in question attempts to locate the URL of the "GeoIP.dat" file:
URL url = ExchangeInterceptor.class.getResource("GeoIP.dat");
However, this call returns null, leaving you perplexed.
After a thorough examination, it was discovered that the Resource Patterns設定 in Intellij Idea might be the culprit. Specifically, it ensures that class.getResource only recognizes and interpret resources that conform to the specified extensions.
To resolve this problem, verify the Resource Patterns setting by navigating to Settings > Build, Execution, Deployment > Compiler > Resource Patterns. Ensure that the extension of the resource you're trying to locate is included within the list of accepted patterns.
Once you've confirmed or added the correct extension, recompile your code to ensure that class.getResource can locate and load the desired resource file.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3