簡體   English   中英

代號一個生成錯誤:建議“使用-source 7”

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

由於在代碼中包含Stringswitch語句,導致出現此特定錯誤。 Java 5(編譯器使用的目標版本)不支持此功能。

另一種解決方法是使用if-else語句而不是switch

確保您正在運行最新的Java版本Java 8 您可以根據需要在此處進行更新。

打開build.xml查找並替換 查找1.5並用1.7或1.8替換(盡管您將必須添加構建提示 `java.version = 8)。

右鍵單擊您的項目,然后選擇“ 屬性” ,從左窗格中導航到源,然后將源/二進制格式更改為JDK 7JDK 8 (取決於所需的版本)。

切換到Sources下的Libraries並將Java Platform更改為最新版本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM