Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com program not work in command line but works in eclipse
 User Name Remember Me? Password

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 02-19-2011, 01:43 AM PM User | #1 worldtraveller Regular Coder   Join Date: Nov 2010 Location: canada Posts: 131 Thanks: 51 Thanked 0 Times in 0 Posts program not work in command line but works in eclipse Good evening all I have some posted code here for a fraction program in java. Problem is it works only in Eclipse but i am having a hard time to run in it in Command line. Here are the 2 parts of the programs one is called Fraction and second one is Tester Here is the code for Fraction Code: ```package fractions; public class Fraction { // Constructor: sets numerator and denominator public Fraction(int num, int denom) { this.numerator=num; this.denominator=denom; } // Methods /////// // Returns object plus frac1 public Fraction add(Fraction frac1) { int num=this.getNum(); int denom=this.getDenom(); // Check that we have the same denominator for both fractions if (frac1.getDenom()!=denom) { int _denom=denom; num*=frac1.getDenom(); denom*=frac1.getDenom(); frac1=frac1.mult(new Fraction(_denom,_denom)); } num+=frac1.getNum(); return new Fraction(num,denom); } // Returns object minus frac1 public Fraction minus(Fraction frac1) { int num=this.getNum(); int denom=this.getDenom(); // Check that we have the same denominator for both fractions if (frac1.getDenom()!=denom) { int _denom=denom; num*=frac1.getDenom(); denom*=frac1.getDenom(); frac1=frac1.mult(new Fraction(_denom,_denom)); } num-=frac1.getNum(); return new Fraction(num,denom); } // Returns object times frac1 public Fraction mult(Fraction frac1) { int num=this.getNum(); int denom=this.getDenom(); num*=frac1.getNum(); denom*=frac1.getDenom(); return new Fraction(num,denom); } // Returns object divided by frac1 public Fraction div(Fraction frac1) { int num=this.getNum(); int denom=this.getDenom(); num*=frac1.getDenom(); denom*=frac1.getNum(); return new Fraction(num,denom); } // Returns numerator of frac1 public int getNum() { return this.numerator; } // Returns denominator of frac1 public int getDenom() { return this.denominator; } // Data members private int numerator; private int denominator; }``` Ok here is the code for Tester Code: ```package fractions; public class Tester { public static void main(String[] args) { Fraction frac1=new Fraction(1,3); Fraction frac2=new Fraction(2,5); Fraction fracAdd=frac2.add(frac1); Fraction fracMinus=frac2.minus(frac1); Fraction fracMult=frac2.mult(frac1); Fraction fracDiv=frac2.div(frac1); System.out.println(toString(frac2)+" + "+toString(frac1)+" = "+toString(fracAdd)); System.out.println(toString(frac2)+" - "+toString(frac1)+" = "+toString(fracMinus)); System.out.println(toString(frac2)+" * "+toString(frac1)+" = "+toString(fracMult)); System.out.println(toString(frac2)+" / "+toString(frac1)+" = "+toString(fracDiv)); } public static String toString(Fraction frac) { return frac.getNum()+"/"+frac.getDenom(); } }``` So that is that. it somewhat works in Eclipse but not in command line. So i am confused as to what it does not work work there. These are the error messages I get in command line on it For when i got Javac and java Fraction this message i get for it in command line Code: ```Exception in thread "main" java.lang.NoClassDefFoundError: Fraction (wrong name: fractions/Fraction) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access\$000(URLClassLoader.java:58) at java.net.URLClassLoader\$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher\$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248)``` When i javac Tester this is what i get as message Code: ```Tester.java:20: cannot find symbol symbol : class Fraction location: class fractions.Tester public static String toString(Fraction frac) { ^ Tester.java:6: cannot find symbol symbol : class Fraction location: class fractions.Tester Fraction frac1=new Fraction(1,3); ^ Tester.java:6: cannot find symbol symbol : class Fraction location: class fractions.Tester Fraction frac1=new Fraction(1,3); ^ Tester.java:7: cannot find symbol symbol : class Fraction location: class fractions.Tester Fraction frac2=new Fraction(2,5); ^ Tester.java:7: cannot find symbol symbol : class Fraction location: class fractions.Tester Fraction frac2=new Fraction(2,5); ^ Tester.java:9: cannot find symbol symbol : class Fraction location: class fractions.Tester Fraction fracAdd=frac2.add(frac1); ^ Tester.java:10: cannot find symbol symbol : class Fraction location: class fractions.Tester Fraction fracMinus=frac2.minus(frac1); ^ Tester.java:11: cannot find symbol symbol : class Fraction location: class fractions.Tester Fraction fracMult=frac2.mult(frac1); ^ Tester.java:12: cannot find symbol symbol : class Fraction location: class fractions.Tester Fraction fracDiv=frac2.div(frac1); ^ 9 errors``` So thank you all for taking the time to go over this. It is whacking my mind that it works in one spot but not that other, feel free to run this yourself to see what i mean. Thanks all. and thanks for all feedback.
 02-19-2011, 05:39 AM PM User | #2 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,595 Thanks: 4 Thanked 2,597 Times in 2,566 Posts Don't javac Tester unless Fraction has also been compiled. You can compile multiple with `javac /path/to/fractions/*.java` or by creating an argfile. __________________ PHP Code: ``` header('HTTP/1.1 420 Enhance Your Calm');  ```
 Users who have thanked Fou-Lu for this post: worldtraveller (02-19-2011)
 02-19-2011, 04:48 PM PM User | #3 worldtraveller Regular Coder   Join Date: Nov 2010 Location: canada Posts: 131 Thanks: 51 Thanked 0 Times in 0 Posts Regarding the fractions program as first part of TME 4 i am able to compile it in JGRASP but its not working as run in the program. Has anyone got same problem, when i try to run in JGRASP i get error " no main methods or applets found in file" I have a test file to go with this. So now i am confused. keep in mind it does compile though So that is what is going on with it. I can not see where i am going wrong on this. I hope someone else can see the problem?
 02-19-2011, 05:19 PM PM User | #4 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,595 Thanks: 4 Thanked 2,597 Times in 2,566 Posts Have you added your fractions package to the location of your javac as well? You're not clear as to what the problem is here. First you say it doesn't compile, then you say it does compile. I have no idea what jgrasp is, is it a framework, or an IDE or what? If its a framework and its not working, they likely have an interface you need to obey in order to use it with the framework. __________________ PHP Code: ``` header('HTTP/1.1 420 Enhance Your Calm');  ```
 02-19-2011, 09:40 PM PM User | #5 worldtraveller Regular Coder   Join Date: Nov 2010 Location: canada Posts: 131 Thanks: 51 Thanked 0 Times in 0 Posts Well i was wrong it does compile but not able to run the program. It does compile in JGRASP but not able to run, JGRASP is like Eclipse I am not sure what i am doing wrong so if anyone can can u take my code and run it and see what u can come up with as i am out of options now, not working, and frustrated thanks
 08-03-2011, 02:55 AM PM User | #6 nbecker New to the CF scene   Join Date: Dec 2010 Posts: 5 Thanks: 0 Thanked 0 Times in 0 Posts I realize that this is kind of an old thread, but I did a quick search because I'm having the same problem. I have three classes located in the same directory, they all compile and run fine from Eclipse, but when I try to run the program from terminal, I get almost the exact same error messages that worldtraveller was getting. Not sure what I'm doing wrong, as I can compile them all at once, but I cannot run the main program. If this issue was resolved, I'd love to hear how exactly. Maybe I'm missing something. I'm kind of a newbie at both programming and this forum.

 Bookmarks

 Tags eclipse, fractions, java

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 05:44 PM.