amiregelz
amiregelz

Reputation: 1845

Import doesn't work in a similar class

So I have a project in the Eclipse, with 2 classes, both of them contain an import of another library called Bucket. Everything works perfectly, but in the third class I created, the import doesn't seem to work and when I create new objects it says the constructor is undefined, while the code is similar among those 3 classes.

I'm sure it's a silly Eclipse problem, what can cause this? Thanks

Edit - Here is the code:

This class works fine:

import java.util.*;
import unit4.bucketLib.Bucket;

public class Buck2
{
    static Scanner reader = new Scanner(System.in);
    public static void main(String [ ] args)
    {
        int n, i;
        System.out.println("Type a number of buckets to create");
        n = reader.nextInt();

        Bucket[] bucks = new Bucket[n];

        for (i = 0; i < n; i++)
            bucks[i] = new Bucket(20, "Bucket" + (i+1));

This class has errors:

import java.util.*;
import unit4.bucketLib.Bucket;
public class Buck3
{
    static Scanner reader = new Scanner(System.in);
    public static void main(String [ ] args)
    {
        int n, i;
        System.out.println("Type a number of buckets to create");
        n = reader.nextInt();

        Bucket[] bucks = new Bucket[n];

        double rdmcap, rdmfill;

        for (i = 0; i < n; i++)
        {
            rdmcap = (Math.random() * 10);
            bucks[i] = new Bucket(rdmcap, "Bucket" + (i+1));
            rdmfill = (Math.random() * rdmcap);
            bucks[i].fill(rdmfill);
        }

Upvotes: 0

Views: 361

Answers (1)

Nanne
Nanne

Reputation: 64399

You should show the code that has the problem, but I can hazard a guess:

Are you sure the import doesn't work? Most of the time if it says the constructor is undefined it DID find the class you refer to (otherwise you'd get the error that the class isn't found)

Your call to the constructor probably doesn't have the right parameters: if it expects an Integer, and you provide a String, it cannot find the constructor that asks for a String. Check your constructor-calls!

Upvotes: 3

Related Questions