[英]codename one build error: suggesting “use -source 7”
我正在使用Eclipse和Codename One。 在构建应用程序时,出现以下错误:
-----
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
-----
如何在Eclipse中解决此问题?
谢谢!
有关为什么会发生这种情况的详细说明,请参见下面的说明。
创建新的Codename One项目时,它可以是Java 8项目或Java 5项目。 如果您的IDE在Java 7下运行,则根本不会显示Java 8选项,并且将创建一个Java 5项目。 在模拟器中可以将IDE切换到Java 7,但是在尝试为设备构建时失败!
最好的解决方案是切换到Java 8,您需要验证IDE在内部使用它,在eclipse中这有点棘手,因为您需要编辑ini文件以获取eclipse 。
完成后,您将可以创建一个新项目并选择Java8。或者,您可以编辑该项目并将其配置为使用Java 8,但是不要忘记添加构建提示java.version=8
。
由于在代码中包含String
的switch
语句,导致出现此特定错误。 Java 5(编译器使用的目标版本)不支持此功能。
另一种解决方法是使用if-else
语句而不是switch
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.