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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:34:29+00:00 2026-06-03T13:34:29+00:00

I have written a simple package program: //A simple package package MyPack class Balance

  • 0

I have written a simple package program:


  //A simple package

       package MyPack


       class Balance
       {
        String name;
        double bal;

        Balance(String n, double b)
        {
            name=n;
                    bal=b;
            }

        void show()
            {
            if(bal<0)
            System.out.println("-->");
            System.out.println(name+ ": $:" +bal);
        }
        }

        class AccountBalance
        {
            public static void main(String args[])
            {
                       Balance current[]=new Balance[3];
                    current[0]=new Balance("A.K.Juwatkar",123.123);
                    current[1]=new Balance("A.P.Dhoke",345.67);
                    current[2]=new Balance("Anil Sarang",100.98);

                    for(int i=0;i<3;i++)
                current[i].show();
               }
        }

I am using Ubuntu 10.04 &
When i compile it using

java MyPack.AccountBalance

I get the following message:

Exception in thread "main" java.lang.NoClassDefFoundError: MyPack/AccountBalance
Caused by: java.lang.ClassNotFoundException: MyPack.AccountBalance
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: MyPack.AccountBalance. Program will exit.

What is wrong? Please help me out.
I have installed openjdk, do i need to install anything else??
I am using Ubuntu 10.04, kindly help me out

  • 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-03T13:34:31+00:00Added an answer on June 3, 2026 at 1:34 pm

    Best is to compile and run the classes from outside the packages :

    First you compile with javac :

    $javac MyPack/AccountBalance.java
    

    this will create a new file in the MyPack folder called AccountBalance.class

    then you can run it :

    $java MyPack.AccountBalance
    

    By the way: it is discouraged to have package names start with a capital.

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

Sidebar

Related Questions

I have written simple j2me program with LWUIT package.I have added one Form in
I have written a simple C++ shell program to parse large XML files and
I have written a simple Java class to generate the hash values of the
I have written a simple OpenGL program in C++ that displays a line joining
I have written a Java program which I package and run from a JAR
I have written a simple server - client program with Swing interface using singleton
i have written a sample program.below: #include<iostream> #include<string> #include<set> using namespace std; int main()
I have written simple code to get content from xml file to php. $xml
I have written a simple Java dispatcher with a daemon thread to handle the
I have written a simple WCF service that accepts and stores messages. It works

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.