[英]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.