简体   繁体   English

代号一个生成错误:建议“使用-source 7”

[英]codename one build error: suggesting “use -source 7”

I am using Eclipse and Codename One. 我正在使用Eclipse和Codename One。 When I am building my application I am getting the following error: 在构建应用程序时,出现以下错误:

-----
Buildfile: C:\P\eclipse_workspace\HelloWorld\build.xml

jar:
        [echo] Compile is forcing compliance to the supported API's/features for maximum device compatibility. This allows smaller
        [echo]          code size and wider device support
        [copy] Copying 3 files to C:\P\eclipse_workspace\HelloWorld\build\tmp
       [javac] C:\P\eclipse_workspace\HelloWorld\build.xml:147: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
       [javac] Compiling 39 source files to C:\P\eclipse_workspace\HelloWorld\build\tmp
       [javac] warning: [options] source value 1.5 is obsolete and will be removed in a future release
       [javac] warning: [options] target value 1.5 is obsolete and will be removed in a future release
       [javac] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
       [javac] C:\P\eclipse_workspace\HelloWorld\src\com\mycompany\lectures\Starter.java:197: error: strings in switch are not supported in -source 1.5
       [javac]      switch(option){
       [javac]            ^
       [javac]   (use -source 7 or higher to enable strings in switch)
       [javac] Note: Some input files use or override a deprecated API.
       [javac] Note: Recompile with -Xlint:deprecation for details.
       [javac] 1 error
       [javac] 3 warnings

BUILD FAILED
C:\P\eclipse_workspace\HelloWorld\build.xml:147: Compile failed; see the compiler error output for details.

Total time: 1 second
-----

How can I fix this problem in Eclipse? 如何在Eclipse中解决此问题?

Thanks! 谢谢!

For a thorough explanation of why this is happening see the explanation below. 有关为什么会发生这种情况的详细说明,请参见下面的说明。

When you create a new Codename One project it can either be a Java 8 project or a Java 5 project. 创建新的Codename One项目时,它可以是Java 8项目或Java 5项目。 If your IDE is running under Java 7 you won't be presented with the Java 8 option at all and a Java 5 project will be created. 如果您的IDE在Java 7下运行,则根本不会显示Java 8选项,并且将创建一个Java 5项目。 Switching the IDE to Java 7 will work in the simulator but fail when you try to build for devices! 在模拟器中可以将IDE切换到Java 7,但是在尝试为设备构建时失败!

The best solution is to switch to Java 8, you need to verify that your IDE is using it internally, in eclipse this is a bit tricky as you need to edit the ini file for eclipse . 最好的解决方案是切换到Java 8,您需要验证IDE在内部使用它,在eclipse中这有点棘手,因为您需要编辑ini文件以获取eclipse

Once you do that you will be able to create a new project and select Java 8. Alternatively you can just edit the project and configure it to use Java 8 but then don't forget to add the build hint java.version=8 . 完成后,您将可以创建一个新项目并选择Java8。或者,您可以编辑该项目并将其配置为使用Java 8,但是不要忘记添加构建提示java.version=8

You got this specific error because of a switch statement involving a String in your code. 由于在代码中包含Stringswitch语句,导致出现此特定错误。 It is not supported in Java 5 (the target version used by your compiler). Java 5(编译器使用的目标版本)不支持此功能。

An alternative workaround is to use if-else statements instead of the switch . 另一种解决方法是使用if-else语句而不是switch

Ensure that you are running the latest Java version Java 8 . 确保您正在运行最新的Java版本Java 8 You can update here , if necessary. 您可以根据需要在此处进行更新。

Open build.xml and do find and replace . 打开build.xml查找并替换 Look for 1.5 and replace with 1.7 or 1.8 (though you will have to add a build hint `java.version=8). 查找1.5并用1.7或1.8替换(尽管您将必须添加构建提示 `java.version = 8)。

Right-click on your project and choose Property , navigate to sources from the left pane and change your source/Binary Format to JDK 7 or JDK 8 (depending on the version you want). 右键单击您的项目,然后选择“ 属性” ,从左窗格中导航到源,然后将源/二进制格式更改为JDK 7JDK 8 (取决于所需的版本)。

Switch to Libraries right under Sources and change your Java Platform to the latest 切换到Sources下的Libraries并将Java Platform更改为最新版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM