Java编译错误在命令提示符下:类文件的版本52.0错误,应为50.0 [英] Java Compiling Error in Command prompt: class file has wrong version 52.0, should be 50.0

查看:1396
本文介绍了Java编译错误在命令提示符下:类文件的版本52.0错误,应为50.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个java库程序,并在另一个java程序中使用它作为.jar文件。我的IDE是NetBeans。我尝试了通过命令行相同的概念,我得到以下错误:


类文件有错误的版本52.0,应该是50.0请删除或
确保它出现在类路径的正确子目录中。
import Demo1_Lib.Test1;
^


这是我的步骤。



步骤1:在NetBeans IDE中创建以下类库。

  package Demo1_Lib; 

/ **
*
* @author tveluppillai
* /
public class Test1
{
public void print )
{
System.out.println(hello);
}
}

步骤2:在netbeans上的一个java项目并添加jar文件。 (Test1.jar)并使用类库函数。

  package test2; 

import Demo1_Lib.Test1;

/ **
*
* @author tveluppillai
* /

public class Test2
{

/ **
* @param参数命令行参数
* /
public static void main(String args [])
{
Test1 obj = new Test1();
obj.print();
}

}

,它给我在NetBeans中的正确输出



但是,当我做同样的事情使用命令提示符我得到错误。



我使用以下命令来编译和运行它。

  javac -cp C:\\Demo_Lib\\Test\\Test1.jar Test2.java 

我收到以下错误:


类文件具有错误的版本52.0,应该是50.0请删除或
确保它出现在类路径的正确的子目录中。
import Demo1_Lib.Test1;
^


我缺少什么?

解决方案

您正试图使用​​运行时/编译器JRE / JDK 6运行/引用使用JDK 8编译的类。 p>

命令行使用的Java可能与NetBeans使用的版本不同。



a href =http://en.wikipedia.org/wiki/Java_class_file =nofollow> Java类文件列出数字的含义。



下载JDK8,或者如果您已经拥有它,请将其添加到您的路径并设置JAVA_HOME。



在Unix中:

  export JAVA_HOME = directory 
export PATH = $ PATH:$ JAVA_HOME / bin


I create a java library program and used it in another java program as .jar file. My IDE is NetBeans. I tried the same concept via command line and I got the following error:

class file has wrong version 52.0, should be 50.0 Please remove or make sure it appears in the correct sub directory of the class path. import Demo1_Lib.Test1; ^

This are my steps.

Step 1: Created the following class library in NetBeans IDE.

  package Demo1_Lib;

 /**
  *
  * @author tveluppillai
 */
public class Test1 
{
  public void print() 
  {
    System.out.println("hello");
  }    
 }

Step 2: Create a java project on netbeans and add the jar file. (Test1.jar) and consume the class library function.

 package test2;

 import Demo1_Lib.Test1;

 /**
 *
    * @author tveluppillai
 */

  public class Test2 
  {

   /**
    * @param args the command line arguments
    */
    public static void main(String args[]) 
   {
     Test1 obj = new Test1();
     obj.print();       
    }

 } 

This compiles fine and when I ran, it gives me the right output in NetBeans

However, when I do the same thing using command prompt I got error.

I used the following command to compile and run it.

javac -cp C:\\Demo_Lib\\Test\\Test1.jar Test2.java

I got the following error:

class file has wrong version 52.0, should be 50.0 Please remove or make sure it appears in the correct sub directory of the class path. import Demo1_Lib.Test1; ^

What am I missing?

解决方案

You are trying to run/reference a class compiled with JDK 8 using a runtime/compiler JRE/JDK 6.

The Java being used by the command line is probably a different version than the one used by NetBeans.

See Java class file for a list of what the numbers mean.

Download JDK8, or if you already have it, add it to your path and set JAVA_HOME.

In Unix:

export JAVA_HOME=directory
export PATH=$PATH:$JAVA_HOME/bin

这篇关于Java编译错误在命令提示符下:类文件的版本52.0错误,应为50.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆