Packages
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   P_T
Posted On:   Tuesday, June 19, 2001 10:57 AM

I am getting a error message, when I try to run the following program, though it seems to compile fine. package MyPack; class Balance { String name; double bal; Balance(String n, double b) { name = n; bal = b; } void show() { if(bal <0) System.out.print("-->>"); System.out.println(name + ": $" + bal); } } class AccountBalance { public static void main(String args[]) { Balance current[] = new Balance[3];    More>>

I am getting a error message, when I try to run the following program, though it seems to compile fine.


package MyPack;



class Balance {


String name;


double bal;



Balance(String n, double b) {


name = n; bal = b;


}




void show()


{ if(bal <0)


System.out.print("-->>");


System.out.println(name + ": $" + bal);



}


}




class AccountBalance {


public static void main(String args[]) {


Balance current[] = new Balance[3];


current[0] = new Balance("K.J.Fielding", 123.23);


current[1] = new Balance("Will Tell", 157.02);


current[2] = new Balance("Tom Jackson", -12.33);



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


}


}





My working directory is C:jdk1.3.1libclasses. I have created a subdirectory called MyPack under classes.



The error message is as follows :-


Exception in thread "main" java.lang.NoClassDefFoundError: MyPack/AccountBalance


Please advise. Regards,

   <<Less

Re: Packages

Posted By:   Kesavan_Srinivasan  
Posted On:   Tuesday, June 19, 2001 09:30 PM

Hi

This works perfectly for me.

Follow the steps:


  1. Compile using,
    d:dir>javac -d . AccountBalance.java
  2. Setting the classpath
    d:dir>set classpath=%classpath%;.;..;
  3. Execute the program,
    d:dir>java MyPack.AccountBalance


Hope this solves ur problem. If u hv further problems write me at kesavansrini@yahoo.co.in

Kesavan.

Re: Packages

Posted By:   Thomas_Dietrich  
Posted On:   Tuesday, June 19, 2001 01:43 PM

Hello PT,


I think making AccountBalance public might help.


My 2 cents. :)


Sincerely,


Thomas Dietrich

About | Sitemap | Contact