1

My class object is not loading for some reason. I've made 3 methods in the second class and I'm trying to use them in the first class, but I'm getting exception errors. Here's my first class:

public class MyFish extends Panel implements Runnable, KeyListener {

public static void main(String args[]) {

    EFish.loadEFish(EFish.eFish); // load the EFish objects
    EFish.loadEFishThread(EFish.eFishThread); // load the EFish threads
    EFish.startEFishThread(EFish.eFishThread); // start the EFish threads

}
}

Here's my second class:

public class EFish implements Runnable {

static EFish eFish[] = new EFish[20];
static Thread eFishThread[] = new Thread[20];

static void loadEFish(EFish i[]) {

    for (int j = 0; j < i.length; j++) {
        i[j] = new EFish();
    }
}

static void loadEFishThread(Thread i[]) {

    for (int j = 0; j < i.length; j++) {
        i[j] = new Thread();
    }
}

static void startEFishThread(Thread i[]) {

    for (int j = 0; j < i.length; j++) {
        i[j].start();
    }
}
}

Here's the exception error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The method loadEFish(EFish[]) is undefined for the type EFish
eFishThread cannot be resolved or is not a field
eFishThread cannot be resolved or is not a field
at fishy.MyFish.main(MyFish.java:103)
Skillet
  • 237
  • 1
  • 4
  • 16
  • 3
    Have you compiled `EFish` before `MyFish` and when compiling `MyFish` you're making sure that `EFish` is available in the classpath and that `EFish` is not redefined elsewhere in `MyFish` or in that package? – Luiggi Mendoza Apr 22 '15 at 18:48
  • 1
    You're trying to *execute* code that doesn't even *compile*. Don't do that. Read the error messages from the compiler, and fix them all. Once done, then run the program. – JB Nizet Apr 22 '15 at 18:49
  • 1
    First thing to learn: don't try to run code that doesn't compile. Next, even though it's valid to use the array syntax you're using, I'd *strongly* recommend using `Thread[] i` etc instead of `Thread i[]`. – Jon Skeet Apr 22 '15 at 18:49
  • They're all in the same package. – Skillet Apr 22 '15 at 18:50
  • Delete all your *.class files, and recompile everything. Fix the compile errors first. – Jesper Apr 22 '15 at 18:52
  • Eclipse automatically compiles everything for me. How do I find the compile errors? – Skillet Apr 22 '15 at 18:54
  • And just a side note on coding style: the names that you are using for your methods and variables are horrible. There is really no sense in repeating all over the place that you like the term "efish", EFish, eFish ... ;-) – GhostCat Apr 22 '15 at 18:56
  • @Skillet, you are implement Runnable, but where are the `run` methods? – alainlompo Apr 22 '15 at 18:58
  • @alainlompo I do have the run method in my codes, but I didn't show them as people seem to get confuse when there is too much code. I just want to show enough code where the problem is at. But if you want I can show u the run method. – Skillet Apr 22 '15 at 18:59
  • Guys. I did not change anything but after running it several times without changing anything, suddenly the compliation error are gone. Why? – Skillet Apr 22 '15 at 19:03

0 Answers0