使用Web应用程序时java.lang.NullPointerException

时间:2018-07-11 08:04:15

标签: java

我运行代码时遇到java.lang.NullPointerException错误。我不知道问题出在哪里

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WEB-INF/views/home.jsp");
    req.setAttribute("restName", AppConfigPropertyReader.getProperty("RESTAURANT_NAME"));
    req.setAttribute("restDesc", AppConfigPropertyReader.getProperty("RESTAURANT_DESC"));
    req.setAttribute("contact", AppConfigPropertyReader.getProperty("RESTAURANT_CONTACT"));


    dispatcher.forward(req, resp);
}

以及

public static String getProperty(String key) {
    String value = null;
    InputStream input;
    try {
        input = AppConfigPropertyReader.class.getClassLoader().getResourceAsStream(PROPERTY_FILE);
        Properties p = new Properties();
        p.load(input);
        value = p.getProperty(key);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return value;
}

错误正在得到

java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:434)
at java.util.Properties.load0(Properties.java:353)
at java.util.Properties.load(Properties.java:341)
*at com.restaurant.util.AppConfigPropertyReader.getProperty(AppConfigPropertyReader.java:18)*
*at com.restaurant.controller.HomeController.doGet(HomeController.java:23)*
at javax.servlet.http.HttpServlet.service(HttpServlet.java:686)

0 个答案:

没有答案