Java error: cannot find symbol Rational()

812 views Asked by At

I'm only using the acm package as per my instructor's preference.
This program is supposed to allocate 10000 rational objects so that they will become garbage, and then calculate the free memory before and after the use of the garbage collector. Then, it's supposed to print the amount of memory that the garbage collector has cleared.

import acm.program.*;

public class RuntimeGarbage extends ConsoleProgram {
    public void run() {
        println("Allocating 10000 Rational Objects");
        for(int i=1; i==10000; i++) {
            new Rational();
        }
        Runtime myRuntime = Runtime.getRuntime();
        long free_before = myRuntime.freeMemory();
    myRuntime.gc();
    long free_after = myRuntime.freeMemory();
    println("Garbage collection freed" + ((free_after)-(free_before)) + "bytes");
    }
}


The problem with this, is that when i try to compile the code, the cmd shows the following:

:8: error: cannot find symbol 
new Rational(); 
with an arrow right below the R. 

Could it be that the problem is the creation of the objects within the curly brackets?

1

There are 1 answers

1
matcheek On BEST ANSWER

What compiler is saying is that it does not know where the type Rational is defined. Yes, you can create object in the code block of the for loop.

According to google the type Rational is not defined in the package acm

rational site:www-cs-faculty.stanford.edu/~eroberts/jtf/javadoc/student/acm/

so it must have been defined somewhere else.

It does not look it belongs to built-in java types either http://docs.oracle.com/javase/7/docs/api/