2016-03-01 74 views
1

我正在使用Eclipse和Codename One。 當我建立我的申請,我收到以下錯誤:codename one build error:suggest「use -source 7」

----- 
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這個問題呢?

謝謝!

回答

1

有關發生這種情況的詳細解釋,請參閱下面的說明。

當您創建新的Codename One項目時,它可以是Java 8項目或Java 5項目。如果您的IDE在Java 7下運行,則根本不會提供Java 8選項,並且將創建Java 5項目。將IDE切換到Java 7將在模擬器中工作,但在嘗試爲設備構建時會失敗!

最好的解決方案是切換到Java 8,你需要驗證你的IDE在內部使用它,在eclipse中這是有點棘手,因爲你需要編輯ini file for eclipse

一旦你這樣做,你將能夠創建一個新的項目,並選擇Java 8.或者,你可以編輯項目,並配置它使用Java 8,但不要忘記添加生成提示java.version=8

由於在代碼中涉及Stringswitch聲明,您得到了此特定錯誤。 Java 5(編譯器使用的目標版本)不支持它。

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

+0

我編輯了正確的代號一個基於解決方案的答案。原始解決方案對於一般Java項目是正確的,但與Codename One存在細微差異。 –

+0

謝謝!這清除了一切...... – arastirmaci

1

確保您正在運行最新的Java版本Java 8。如有必要,您可以更新here

打開build.xml並確實找到並替換。查找1.5並用1.7或1.8替換(儘管您必須添加一個build hint`java.version = 8)。

您的項目右鍵單擊並選擇物業,從左側窗格中瀏覽到源,改變你的源/二進制格式JDK 7或​​(取決於你想要的版本)。

切換到權下來源,改變你的Java平臺最新

+0

這是__source/Binary Format__選項在哪裏?我找不到它.. –