-1

So I decompiled a jar and imported everything into eclipse, but I have a ton of these really strange errors all over the place.

Error

When I hover over the error on line 279 it says

Cannot reference a field before it is defined

even though it is very clearly defined on the line above I even had one error on a comment saying it could not resolve the variable even though it was commented out.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Zacx
  • 420
  • 5
  • 10
  • 1
    Where is file/2/3/4 declared? – Keno Mar 27 '16 at 23:40
  • 1
    The problem is most likely that all of those files aren't declared before assigning them a value. – Keno Mar 27 '16 at 23:42
  • 1
    Well a decompiler won't get everything perfect usually, so it's just one of those things you have to deal with I guess. – Keno Mar 28 '16 at 00:08

2 Answers2

0

The problem is most likely that all of those files aren't declared before assigning them a value.

E.g file = new File("params"); should be: File file = new File("params");

Keno
  • 2,018
  • 1
  • 16
  • 26
  • I actually just looked into a bit more, and the files are properly declared further down in the class. – Zacx Mar 28 '16 at 00:12
  • 1
    They have to be declared before they are called otherwise it'll cause an error. – Keno Mar 28 '16 at 00:14
  • But that makes no sense, the decompiler just randomly selected all the declarations and moved them to a different spot? – Zacx Mar 28 '16 at 00:16
  • @Zacx Decompilers don't always do their job perfectly. They try to basically reverse-engineer code. Sometimes it works perfectly, sometimes not so much. – Keno Mar 28 '16 at 00:18
  • 3
    @Zacx decompiled code is, at best, a guess based on the information in the byte-code. Byte-code loses information from the original source, so it can never be perfect. If you can replicate this error with a simple example report it as a bug against the decompiler. – dimo414 Mar 28 '16 at 00:45
-1

Java parses fields in-order during compilation, so you can't have fields reference each other in arbitrary order. Your code snippet doesn't appear to have that problem, but if the fields are declared later in the file that would be the cause.

Sometimes Eclipse simply gets out of sync; if you can't see anything wrong, try refreshing the project or rebuilding it.

Community
  • 1
  • 1
dimo414
  • 47,227
  • 18
  • 148
  • 244