Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8906305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:37:11+00:00 2026-06-15T02:37:11+00:00

I have the below class which loads database details from a properties file. When

  • 0

I have the below class which loads database details from a properties file. When the file “dao.properties” is missing the class should throw a DAOConfigurationException but instead I am getting

    javax.servlet.ServletException: Servlet execution threw an exception
root cause

java.lang.ExceptionInInitializerError
    com.clone.dao.DAOFactory.getInstance(DAOFactory.java:19)
    com.clone.controller.register.doPost(register.java:35)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

com.clone.dao.DAOConfigurationException: Properties file dao.properties not found in classpath.
    com.clone.dao.DAOProperties.<clinit>(DAOProperties.java:15)
    com.clone.dao.DAOFactory.getInstance(DAOFactory.java:19)
    com.clone.controller.register.doPost(register.java:35)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

and in subsequent requests I am getting this exeception

javax.servlet.ServletException: Servlet execution threw an exception
root cause

java.lang.NoClassDefFoundError: Could not initialize class com.clone.dao.DAOProperties
    com.clone.dao.DAOFactory.getInstance(DAOFactory.java:19)
    com.clone.controller.register.doPost(register.java:35)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

This is my code

package com.clone.dao;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class DAOProperties {
    private static final String PROPERTIES_FILE = "dao.properties";
    private static final Properties PROPERTIES = new Properties();
<b> static{
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        InputStream propertiesFile = classloader.getResourceAsStream(PROPERTIES_FILE);

        if(propertiesFile==null){
            throw new DAOConfigurationException("Properties file "+PROPERTIES_FILE+" not found in classpath.");
        } 
        try {
            PROPERTIES.load(propertiesFile);
        } catch (IOException e) {
            throw new DAOConfigurationException("Cannot load properties file '"+PROPERTIES_FILE+"'.", e);
        }
    }
</b>
private String specificKey;


    public DAOProperties(String specificKey)
    {
        this.specificKey=specificKey;
    }

    public String getProperty(String key) throws DAOConfigurationException {
        String fullKey = specificKey+"."+key;
        String property = PROPERTIES.getProperty(fullKey);
        if(property==null||property.trim().length()==0){
            throw new DAOConfigurationException("Property '"+fullKey+"' is missing in properties file '"+
                                                        PROPERTIES_FILE+"'.");
        }
        return property;
    }

}

Guys, please explain whats happening this is a lot confusing

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:37:12+00:00Added an answer on June 15, 2026 at 2:37 am

    It is throwing a DAOConfigurationException:

    com.clone.dao.DAOConfigurationException: Properties file dao.properties
         not found in classpath.
    

    However, that’s being wrapped up in an java.lang.ExceptionInInitializerError because your DAOFactory is trying to use DAOProperties. The DAOProperties class can’t be initialized properly because the static initializer fails, and ExceptionInInitializerError is exactly what gets thrown when an static initializer fails.

    Perhaps you shouldn’t be doing this within the static initializer?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data structure which is as given below: class File { public
I have a listView which loads data from SQLite database and right now I
I have two async classes in my application which you can see below class
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I have abstract BaseController, which basically looks like below: public abstract class BaseController :
I have class like this below shown. which contains the shopping items where the
currently I have a web which loads excel spreadsheet data into SQL database. When
I have a class which enables forms with a file-type input to be submitted
I have below code: class Program { static void Main(string[] args) { Task[] tasks
I have a class like the one below: class Foo { private: std::map<std::string, Bar*>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.