943,778 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 742
  • Java RSS
Sep 22nd, 2009
0

Help, no main classes found

Expand Post »
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>_>

Java Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DemonixXV2 is offline Offline
9 posts
since Aug 2009
Sep 22nd, 2009
0

Re: Help, no main classes found

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?
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,374 posts
since Jan 2008
Sep 22nd, 2009
0

Re: Help, no main classes found

I want to run it in netbeans, to see if I get the result I want.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DemonixXV2 is offline Offline
9 posts
since Aug 2009
Sep 22nd, 2009
0

Re: Help, no main classes found

Click to Expand / Collapse  Quote originally posted by DemonixXV2 ...
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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,374 posts
since Jan 2008
Sep 22nd, 2009
0

Re: Help, no main classes found

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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DemonixXV2 is offline Offline
9 posts
since Aug 2009
Sep 22nd, 2009
0

Re: Help, no main classes found

Click to Expand / Collapse  Quote originally posted by DemonixXV2 ...
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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,374 posts
since Jan 2008
Sep 22nd, 2009
0

Re: Help, no main classes found

Cool thxz, this error is gone:
class Amicable is public, should be declared in a file named Amicable.java

And it works!
Java Syntax (Toggle Plain Text)
  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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DemonixXV2 is offline Offline
9 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Menu Not Displaying
Next Thread in Java Forum Timeline: Compiling issue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC