Help, no main classes found

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2009
Posts: 9
Reputation: DemonixXV2 is an unknown quantity at this point 
Solved Threads: 0
DemonixXV2 DemonixXV2 is offline Offline
Newbie Poster

Help, no main classes found

 
0
  #1
Sep 22nd, 2009
Ok, I've got this code, it says that there are no main classes and that public class Amicable; class Amicable is public, should be declared in a file named Amicable.java, but the file name is Amicable... Any help would greatly help me, since I have same prob. with another file>_>

  1. public class Amicable
  2. {
  3. public Amicable() {
  4. }
  5. int duplicates = 0;
  6.  
  7. public int findAddFactors(int num)
  8. {
  9. int factorSum = 1;
  10. for (int i=2; i<=(num /2); i++)
  11. {
  12. if ((num%i)==0)
  13. factorSum+=i;
  14. }
  15. return factorSum;
  16. }
  17. public String areAmicable(int num)
  18. {
  19. if (num!=duplicates)
  20. {
  21. int pair1 = findAddFactors(num);
  22. int pair2 = findAddFactors(pair1);
  23. if ((num==pair2) && (pair1!=pair2))
  24. {
  25. duplicates = pair1;
  26. return "("+pair2+","+pair1+")";
  27. }
  28. else
  29. return null;
  30. }
  31. else
  32. return null;
  33. }
  34.  
  35. public static void main(String args[])
  36. {
  37. Amicable test = new Amicable();
  38. for (int i=1; i<=100000;i++)
  39. {
  40. String res = test.areAmicable(i);
  41. if (res!=null)
  42. System.out.println(res);
  43. }
  44. }
  45. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Help, no main classes found

 
0
  #2
Sep 22nd, 2009
The above code should be in a file called "Amicable.java". To compile, type "javac Amicable.java". This should create a file called "Amicable.class". To run it, type "java Amicable".


Is that what you are doing?
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 9
Reputation: DemonixXV2 is an unknown quantity at this point 
Solved Threads: 0
DemonixXV2 DemonixXV2 is offline Offline
Newbie Poster

Re: Help, no main classes found

 
0
  #3
Sep 22nd, 2009
I want to run it in netbeans, to see if I get the result I want.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Help, no main classes found

 
0
  #4
Sep 22nd, 2009
Originally Posted by DemonixXV2 View Post
I want to run it in netbeans, to see if I get the result I want.
Still needs to be in a file called "Amicable.java" if it is not already. If it's in NetBeans, you can ignore the rest of my earlier post.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 9
Reputation: DemonixXV2 is an unknown quantity at this point 
Solved Threads: 0
DemonixXV2 DemonixXV2 is offline Offline
Newbie Poster

Re: Help, no main classes found

 
0
  #5
Sep 22nd, 2009
And how do I do that?

First time using netbeans and coding in java lang.

I right clicked on the project name and changed it to Amicable.java and the output folder, that didn't help...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Help, no main classes found

 
0
  #6
Sep 22nd, 2009
Originally Posted by DemonixXV2 View Post
And how do I do that?

First time using netbeans and coding in java lang.

I right clicked on the project name and changed it to Amicable.java and the output folder, that didn't help...
Don't change the project name. You can name the project whatever you'd like. You have a couple of options.

You can go into the src folder for the project and rename the file to Amicable.java manually there (not through NetBeans).

NetBeans may let your "refactor" the name to the correct name by right-clicking the file (though I've never tried it where it was a matter of not having the .java extension at the end).

Delete the file and create a new CLASS (not a new project) called Amicable. NetBeans will add the .java extension automatically. Then copy and paste the code into the new file.


So it's a matter of finding out what the file name is now and seeing
  1. Does it end in .java?
  2. Is the part before the dot "Amicable"?
Last edited by VernonDozier; Sep 22nd, 2009 at 8:41 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 9
Reputation: DemonixXV2 is an unknown quantity at this point 
Solved Threads: 0
DemonixXV2 DemonixXV2 is offline Offline
Newbie Poster

Re: Help, no main classes found

 
0
  #7
Sep 22nd, 2009
Cool thxz, this error is gone:
class Amicable is public, should be declared in a file named Amicable.java

And it works!
  1. (220,284)
  2. (1184,1210)
  3. (2620,2924)
  4. (5020,5564)
  5. (6232,6368)
  6. (10744,10856)
  7. (12285,14595)
  8. (17296,18416)
  9. (63020,76084)
  10. (66928,66992)
  11. (67095,71145)
  12. (69615,87633)
  13. (71145,67095)
  14. (76084,63020)
  15. (79750,88730)
  16. (87633,69615)
  17. (88730,79750)
  18. BUILD SUCCESSFUL (total time: 25 seconds)

Now I can fix my other problems, thxz a bunch!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 317 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC