nus-cs2103-AY1718S1 / forum

Discussion Forum
5 stars 0 forks source link

getResource() returns null #95

Closed shuang-yang closed 6 years ago

shuang-yang commented 6 years ago

In executing the following code (in HelpWindow.java): String userGuideUrl = getClass().getResource(USERGUIDE_FILE_PATH).toString(); getResource(USERGUIDE_FILE_PATH) always returns null, which leads to a NullPointerExeption and thus failure of the HelpWindowTest.

USERGUIDE_FILE_PATH is declared as as follows: public static final String USERGUIDE_FILE_PATH = "/docs/UserGuide.html";

It seems the problem is that "/docs" directory is not under "/src/main/resources" directory, because when I copied the UserGuide file to "/src/main/resources" directory and removed "/docs" from the file path, the code compiles and the test is passed.

May I know why getResource() is used here when "/docs" is not under the "src/main/resource" directory? Or am I missing something here?

Zhiyuan-Amos commented 6 years ago

Open a console and run the command gradlew processResources (Mac/Linux: ./gradlew processResources). It should finish with the BUILD SUCCESSFUL message. This will generate all resources required by the application and tests.

Did you run processResources as mentioned in the setting up instructions in Developer Guide?

damithc commented 6 years ago

May I know why getResource() is used here when "/docs" is not under the "src/main/resource" directory?

@Zhiyuan-Amos what's the answer this this question?

shuang-yang commented 6 years ago

Hi @Zhiyuan-Amos seems this is indeed the problem. @damithc I think the problem is that I did not run the processResources command successfully because the command will generate the /docs directory under “src/main/resources".

Thanks for the help!!

damithc commented 6 years ago

Closing because this seems to be resolved. Please reopen if still not resolved.