• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cant find the error in this  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is this :





And when i compile it it gives me the errors:
RuntimeGarbage.java7 : error: constructor Rational is class Rational cannot be applied to given types :
new Rational();

required: int, int
found:no arguments
reason: actual and formal argument lists differ in length


I don't understand what i have done wrong...
 
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the javadocs of the "Rational" class. It does not seem to have a no-argument constructor.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I took your code, removed the 'color' tags, and put 'code' tags around the whole thing. This preserves your formatting and makes it easier to read. It's also MUCH simpler than inserting those 20 or so other tags.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides what Ulf said, this for loop is wrong:

This does not loop 10000 times, it loops zero times! This means:

set i to 1
loop while i is equal to 10000

It stops immediately because i is 1, not 10000. you should do this instead:

set i to 1
loop while i is less than or equal to 10000

But besides this, this program might not show you how much memory is being used and cleaned up by the garbage collector. The JVM might be smart enough to see that you're not doing anything with the objects in the loop and might optimize them away, so that it will look like they are not using any memory at all.
 
Aggelos Sfakianos
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i made the changes you said jesper but still it gives me the same error at the compile:

RuntimeGarbage.java7 : error: constructor Rational is class Rational cannot be applied to given types :
new Rational();

required: int, int
found:no arguments
reason: actual and formal argument lists differ in length


and i dont know how to fix this
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have documentation for that class? Assuming that it represents a rational number, then it doesn't make sense to create such an object without specifying the numerator and denominator. That is probably what the missing parameters in the constructors are about.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this it? http://stackoverflow.com/questions/20850815/java-error-cannot-find-symbol-acm

If so, it has indeed just one constructor, and that takes two parameters. So "new Rational()" is not going to work.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the "Rational" class? You must have either the source code or documentation on it, since it is not in the Java API.

what that error is telling you is that you are trying to create a Rational object by doing this:



However, the Rational object can only be created if you pass it two ints. My GUESS is that you need to pass it a numerator and a denominator, but without seeing the code, specs, or API on it, we have no way to know.

also note that even if you get it to compile, it won't work. that line creates the object, but since you don't save a reference to it anywhere, it is lost and immediately available for garbage collection.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!