Reputation: 8623
I am learning Java from scratch. I installed the JDK, and I got the Hello World Program running. I am trying to run a simple accountdemo program. In Account.java, I have :
public class Account
{
protected double balance;
// Constructor to initialize balance
public Account( double amount )
{
balance = amount;
}
// Overloaded constructor for empty balance
public Account()
{
balance = 0.0;
}
public void deposit( double amount )
{
balance += amount;
}
public double withdraw( double amount )
{
// See if amount can be withdrawn
if (balance >= amount)
{
balance -= amount;
return amount;
}
else
// Withdrawal not allowed
return 0.0;
}
public double getbalance()
{
return balance;
}
}
On compiling this, I got the Account.class. In accountdemo.java, I have this
class AccountDemo
{
public static void main(String args[])
{
Account my_account = new Account();
my_account.deposit(250.00);
System.out.println("Current balance " + my_account.getbalance());
my_account.withdraw(80.00);
System.out.println("Remaining balance" + my_account.getbalance());
}
}
On compiling this, I got AccountDemo.class. But, when I try to run this as an application, I get the error java.lang.NoClassDefFoundError: C:\Users\roymustang/NT\Documents\javaprogram\accountdemo/java
I have set the classpath to : C:\Users\roymustang.NT\Documents\javaprogram
Am I missing anything obvious? Like mismatched uppercase or something?
EDIT : Not homework, just trying to learn.
I am using Textpad, http://www.textpad.com/ . It has an option run commands. So, I have configured it to run javac.exe (C:\Program Files\SDK\jdk\bin\javac.exe $File $FileDir
)
and run as application by java.exe ( C:\Program Files\SDK\jdk\bin\java.exe $File $FileDir
)
Upvotes: 2
Views: 186
Reputation: 2068
Hi there I'll assume that you are trying to run this using no java IDE e.g. Eclipse or Netbeans. I tested your code and they worked just fine.
C:>java AccountDemo Current balance 250.0 Remaining balance170.0
Your error Message is:
java.lang.NoClassDefFoundError: C:\Users\roymustang/NT\Documents\javaprogram\accountdemo/java
meaning you used:
java accountdemo
to run your program. Remember that Java is case sensitive this can be corrected by using this.
java AccountDemo
Happy Coding ^_^
Upvotes: 3