Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Java "bad class file" issue (http://www.chiefdelphi.com/forums/showthread.php?t=142125)

Ltwolf20 19-01-2016 09:31

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.

codedr 19-01-2016 11:48

Re: Java "bad class file" issue
 
Are you compiling with Java-6?
Class file version 52 needs to be compiled with java-8.

Ltwolf20 19-01-2016 15:35

Re: Java "bad class file" issue
 
Quote:

Originally Posted by codedr (Post 1526625)
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?

codedr 19-01-2016 20:18

Re: Java "bad class file" issue
 
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

Ltwolf20 19-01-2016 21:50

Re: Java "bad class file" issue
 
Quote:

Originally Posted by codedr (Post 1526893)
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

codedr 19-01-2016 22:31

Re: Java "bad class file" issue
 
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.

Ltwolf20 19-01-2016 23:58

Re: Java "bad class file" issue
 
Quote:

Originally Posted by codedr (Post 1526972)
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=""/> -->

<!-- By default the target is set to 10.TE.AM.2 -->
<!-- <property name="target" value=""/> -->

<!-- Any other property in build.properties can also be overridden. -->

<property file="${user.home}/wpilib/wpilib.properties"/>
<property file="build.properties"/>
<property file="${user.home}/wpilib/java/${version}/ant/build.properties"/>

<import file="${wpilib.ant.dir}/build.xml"/>

</project>

codedr 20-01-2016 08:28

Re: Java "bad class file" issue
 
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?

Ltwolf20 20-01-2016 12:39

Re: Java "bad class file" issue
 
Quote:

Originally Posted by codedr (Post 1527118)
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?

codedr 21-01-2016 08:42

Re: Java "bad class file" 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.

Ltwolf20 21-01-2016 20:11

Re: Java "bad class file" issue
 
Quote:

Originally Posted by codedr (Post 1527703)
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?

codedr 22-01-2016 20:50

Re: Java "bad class file" issue
 
I doubt re-installing eclipse is going to fix compiling instructions that are contained within the source code that you are trying to compile.

Ltwolf20 23-01-2016 10:37

Re: Java "bad class file" issue
 
target="${ant.java.version}"
source="${ant.java.version}"

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

codedr 23-01-2016 12:46

Re: Java "bad class file" issue
 
Does this work?

from:
http://stackoverflow.com/questions/9...g-java-version

- 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

fovea1959 24-01-2016 09:55

Re: Java "bad class file" issue
 
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?

Ltwolf20 25-01-2016 00:43

Re: Java "bad class file" issue
 
Thanks so much for all your help guys, apologies for the trouble. I simply had the wrong version set to default. Thanks again:D


All times are GMT -5. The time now is 11:53.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi