reset password
Author Message
fyang15
Posts: 35
Posted 16:42 Mar 12, 2020 |

To read the file through scanner in init(), I use:

File file = new File(getServletContext().getRealPath("/WebContent/DrivingTest.txt"));

However, Eclipse refuses to comply and keeps throwing NPE even though this is exactly the code we are told to use. Any idea how to fix it?

Last edited by fyang15 at 16:42 Mar 12, 2020.
Ambujan
Posts: 1
Posted 16:45 Mar 12, 2020 |

You are probably missing a line in the init method:

super.init( config );

AlbertoLanderos
Posts: 3
Posted 16:49 Mar 12, 2020 |

I had this same error, after you put your text file in web content. Make sure to refresh Eclipse

fyang15
Posts: 35
Posted 16:51 Mar 12, 2020 |
Ambujan wrote:

You are probably missing a line in the init method:

super.init( config );

Thanks! That's exactly the problem.

smallch
Posts: 10
Posted 18:43 Mar 12, 2020 |

Not related to the problem, but drivingtest is supposed to be under web-inf.

semerdjianm
Posts: 11
Posted 19:17 Mar 12, 2020 |
fyang15 wrote:

To read the file through scanner in init(), I use:

File file = new File(getServletContext().getRealPath("/WebContent/DrivingTest.txt"));

However, Eclipse refuses to comply and keeps throwing NPE even though this is exactly the code we are told to use. Any idea how to fix it?

File file = new File(getServletContext().getRealPath("/WEB-INF/DrivingTest.txt"));