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 8579383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:35:56+00:00 2026-06-11T20:35:56+00:00

Possible Duplicate: ClassnotFound exception using java reflection I get exception, java.lang.ClassNotFoundException: SavingAccount , while

  • 0

Possible Duplicate:
ClassnotFound exception using java reflection

I get exception, java.lang.ClassNotFoundException: SavingAccount, while executing the following code:

public class AccountFactory {   
    public void getAccount()
    {
        IAccount account;
        account = null;
     try
        {
         account = (IAccount)Class.forName("SavingAccount").newInstance();
         account.Deposit(500);
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }  
    }

}

What could be the possible reasons causing the error?

this is my saving account code:

public class SavingAccount implements IAccount {
    int money;
    SavingAccount()
    {
        money =0;
    }
    public void WithDraw(int m)
    {
        money--;
    }
    public void Deposit(int m)
    {
        money++;
        System.out.println(money);
    }
}
  • 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-11T20:35:57+00:00Added an answer on June 11, 2026 at 8:35 pm

    The classloader cannot find the SavingsAccount class. You also need to use the fully qualified name for the class when using the Class.forName method as specified in the Java API. A fully qualified class name includes the class name prefixed by the package structure. If your AccountFactory class is always going to create a class of type SavingsAccount every time, I would recommend not even having an AccountFactory class and instead just using:

    IAccount account = new SavingsAccount();
    

    If the posted code is just a snapshot of your class and you do intend to return different types implementing the IAccount interface from your factory you will want to change the getAccount method signature so that it returns an IAccount and not void. You must then use the return statement to return an object that implements the IAccount interface. Such as:

     public IAccount getAccount()
     {
         IAccount account;
         account = null;
         try
            {
             //Notice fully qualified name is used.
             account = (IAccount)Class.forName("org.mydomain.SavingAccount").newInstance();
             account.Deposit(500);
            }
            catch(Exception e)
            {
                System.out.println(e.toString());
            } 
         return account;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Java: Start Mail-Client with Attachment? I need to create a java code
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: ClassNotFoundException com.mysql.jdbc.Driver I have included the mysql-connector-java-5.1.16-bin.jar into my Eclipse library, this
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: Opening url in new tab while i am doing window.open(), my page
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: How to successfully rewrite old mysql-php code with deprecated mysql_* functions? I
Possible Duplicate: Matlab gives wrong answer Can anyone explain to me why the following

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.