Java "bad class file" issue

So I recently attended the 2016 FRC Quick Build and attended the Java programming workshop. After following the code the instructor gave as well as making a few alterations and additions specific to my team’s robot, the code shows no errors or alerts, however when I go to run the program through WPILIB Java Deploy it fails and I get this message.

Buildfile: /Users/ProgrammingWolf/Documents/workspace/TestRobot/build.xml
Trying to override old definition of task classloader
clean:
[delete] Deleting directory /Users/ProgrammingWolf/Documents/workspace/TestRobot/build
compile:
[mkdir] Created dir: /Users/ProgrammingWolf/Documents/workspace/TestRobot/build
[echo] [athena-compile] Compiling src with classpath=/Users/ProgrammingWolf/wpilib/java/current/lib/WPILib.jar:/Users/ProgrammingWolf/wpilib/java/current/lib/NetworkTables.jar: to build
[javac] Compiling 8 source files to /Users/ProgrammingWolf/Documents/workspace/TestRobot/build
[javac] /Users/ProgrammingWolf/Documents/workspace/TestRobot/src/org/usfirst/frc/team4796/robot/OI.java:3: cannot access edu.wpi.first.wpilibj.Joystick
[javac] bad class file: edu/wpi/first/wpilibj/Joystick.class(edu/wpi/first/wpilibj:Joystick.class)
[javac] class file has wrong version 52.0, should be 50.0
[javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
[javac] import edu.wpi.first.wpilibj.Joystick;
[javac] ^

BUILD FAILED
/Users/ProgrammingWolf/wpilib/java/current/ant/build.xml:71: Compile failed; see the compiler error output for details.

Total time: 1 second

I am not quite sure how to fix this error.

Are you compiling with Java-6?
Class file version 52 needs to be compiled with java-8.

I’m not sure, I’m a little new to Java. How would I check that?

On mac in a terminal window, type
echo $JAVA_HOME
javac -version

On windows in a cmd window, type
echo %JAVA_HOME%
javac -version

It will return something like this:
javac -version
javac 1.6.0_33

I get javac 1.8.0_71

Open this file in an editor,
/Users/ProgrammingWolf/wpilib/java/current/ant/build.xml
and look for the javac stanza, and see if there is specifications for either source= or target= or both. For wpilib.jar you are going to need a value for 1.8 for both.

Not sure if I actually went to the right place but here is what I get.

<?xml version=“1.0” encoding=“UTF-8”?>

<project name=“FRC Deployment” default=“deploy”>

<!–
The following properties can be defined to override system level
settings. These should not be touched unless you know what you’re
doing. The primary use is to override the wpilib version when
working with older robots that can’t compile with the latest
libraries.
–>

<!-- By default the system version of WPI is used –>
<!-- <property name=“version” value=“”/> –>

<!-- By default the system team number is used –>
<!-- <property name=“team-number” value=“”/> –>

The error message means the java compiler is in version 1.6 mode and you need it to be in the version 1.8 mode.

According to your compiler output, the failure occurred at line 71 of the file, viz last line of the error log you posted. The file you posted doesn’t have 71 lines.

Perhaps the IDE you are using is setting the java compiler version?

How would I fix this problem? Or check that issue?

You could look through the build xml files for the strings target= and source= in a javac xml stanza.
or
You could tell how to get a copy of the source files you trying to compile or zip them up and upload them to CD so we can see them too.

Do you think I could fix this through uninstalling an reinstalling eclipse and all related files?

I doubt re-installing eclipse is going to fix compiling instructions that are contained within the source code that you are trying to compile.

target="${ant.java.version}"
source="${ant.java.version}"

Is what I get when I look at the build.xml files

Does this work?

from:

  • Right click on the task in your ant build file (build.xml).

  • Mouse over “Run As”, click on “External Tool Configurations…”.

  • Add followings to “Arguments”:

  • Dant.build.javac.target=1.8 -Dant.build.javac.source=1.8

May have multiple Java compilers installed and using the wrong one?

Double check your Installed JREs: go into Eclipse; do Preferences, the work down through the tree Java | Installed JREs. What JREs are installed, and which is the default?

Thanks so much for all your help guys, apologies for the trouble. I simply had the wrong version set to default. Thanks again:D