4

I am using OpenCV for my project and everything works fine except DescriptorExtractor.java. It gives me following error every day:

/opencv/src/org/opencv/features2d/DescriptorExtractor.java
Error:(26, 29) error: illegal forward reference
Error:(27, 29) error: illegal forward reference
Error:(28, 28) error: illegal forward reference
Error:(29, 30) error: illegal forward reference
Error:(30, 30) error: illegal forward reference
Error:(31, 30) error: illegal forward reference
Error:(32, 30) error: illegal forward reference

The file originally look like this:

public class DescriptorExtractor {

    public static final int
            SIFT = 1,
            SURF = 2,
            ORB = 3,
            BRIEF = 4,
            BRISK = 5,
            FREAK = 6,
            AKAZE = 7,
            OPPONENT_SIFT = OPPONENTEXTRACTOR + SIFT,
            OPPONENT_SURF = OPPONENTEXTRACTOR + SURF,
            OPPONENT_ORB = OPPONENTEXTRACTOR + ORB,
            OPPONENT_BRIEF = OPPONENTEXTRACTOR + BRIEF,
            OPPONENT_BRISK = OPPONENTEXTRACTOR + BRISK,
            OPPONENT_FREAK = OPPONENTEXTRACTOR + FREAK,
            OPPONENT_AKAZE = OPPONENTEXTRACTOR + AKAZE;
    private static final int
            OPPONENTEXTRACTOR = 1000;
    protected final long nativeObj;

Everyday I am moving decleration of OPPONENTEXTRACTOR to top of the class and problem goes away. But next day the class reverts to original. On top of the class there is a comment

//
// This file is auto-generated. Please don't modify it!
//

What should I do? How do I prevent this?

UPDATE:

I am using OpenCV for Android 3.0 and Java 7.80

Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
  • 1
    Could this be the cause? http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6676362. Also see http://stackoverflow.com/questions/8234645/illegal-forward-reference-error-for-static-final-fields. Looks like fixed in later versions of Java 7. – JJF Oct 21 '15 at 17:23
  • Please include the versions of **opencv** and **jdk** that you are using – Swastik Padhi Oct 25 '15 at 19:57
  • Well, it seems that they overlooked the best practices in writing classes. Its a valid bug. – Murtaza Khursheed Hussain Oct 26 '15 at 06:48

1 Answers1

0

You have wrong declaration order. It should be like this:

private static final int OPPONENTEXTRACTOR = 1000;

public static final int
        SIFT = 1,
        SURF = 2,
        ORB = 3,
        BRIEF = 4,
        BRISK = 5,
        FREAK = 6,
        AKAZE = 7,
        OPPONENT_SIFT = OPPONENTEXTRACTOR + SIFT,
        OPPONENT_SURF = OPPONENTEXTRACTOR + SURF,
        OPPONENT_ORB = OPPONENTEXTRACTOR + ORB,
        OPPONENT_BRIEF = OPPONENTEXTRACTOR + BRIEF,
        OPPONENT_BRISK = OPPONENTEXTRACTOR + BRISK,
        OPPONENT_FREAK = OPPONENTEXTRACTOR + FREAK,
        OPPONENT_AKAZE = OPPONENTEXTRACTOR + AKAZE;
Serega Maleev
  • 403
  • 5
  • 6