Avery Vine
Avery Vine

Reputation: 164

Error when invoking method - java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>

I've been working on a project that I described in this question that I asked previously. I'm trying to invoke a method from a class who's name is dynamically generated (and the class compiled while the program runs). I call Class watchFace = Class.forName("pebbleos.PebbleOS_" + fileName); followed by currentWatchFace = watchFace.newInstance(); in the method loadWatchFace(), and then in the method runWatchFace() I try to invoke the method using this:

Method method = null;
        try {
            method = currentWatchFace.getClass().getMethod("initializeFace");
        } catch (SecurityException | NoSuchMethodException e) {
            System.out.println("Error");
        }
        method.invoke(currentWatchFace);

My watch face's code is being taken from a text file, which looks like this:

package pebbleos;

public class PebbleOS_Default {

    public PebbleOS_Default () {

    }

    public void initializeFace() {
        System.out.println(“Hello World”);
    }

}

Just a quick note, the above is supposedly the "cause" of this error: java.lang.reflect.InvocationTargetException

Upvotes: 0

Views: 363

Answers (1)

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

From the code you posted, seems that you're using the wrong character that looks a lot like " but they're not the same. Fix it, recompile the code and try again.

Upvotes: 1

Related Questions