0

While working on an Android project, I wanted to use a String switch for identifying which item on a ListView was clicked. Eclipse gave an error saying the targetting JRE had to be at least 1.7 to use this feature and proposed a quick fix: "Change project compliance an JRE to 1.7". I clicked it and the error was gone, but I quickly found out the Android SDK doesn't support Java 1.7. When building and uploading/installing the app, the console gave this error for each activity:

[2013-07-28 14:45:29 - TriviaQuiz] Dx 
trouble processing:
[2013-07-28 14:45:29 - TriviaQuiz] Dx bad class file magic (cafebabe) or version     (0033.0000)
...while parsing com/rob/triviaquiz/BuildConfig.class
...while processing com/rob/triviaquiz/BuildConfig.class

I have tried undoing this quick fix by setting the target JRE to 1.6 by using several methods: Android tools --> Fix project properties, Properties --> Java Compiler, Window --> Preferences --> Java --> Compiler. Resetting the target to 1.6 worked (I think), but I'm still getting the same error.

Does anyone know how to solve this?

EDIT: My problem is not that I want to use an String array or the 1.7 version of Java with Android, but that my Android project doesn't work anymore after the quick fix which changed my target runtime environment to 1.7. I have been able to reset it to version 1.6 (by using the methods above), but the error persists. So I think I this quick fix has messed up more than just changing the targetting Java version, because the builder still thinks I'm targetting Java 1.7 and excludes all my activities from my app (which makes it crash instantaneously)

Community
  • 1
  • 1
Rob
  • 51
  • 11

3 Answers3

1

I had same issue couple of months ago, and as you said:

...but I quickly found out the Android SDK doesn't support Java 1.7.

So you need to develop based on 1.6

Check this, that's the reason why the error appears.

So as recommended, use if/else logic to mimic a switch behavior. It is recommended also for better performance.

Community
  • 1
  • 1
unmultimedio
  • 1,224
  • 2
  • 13
  • 39
0

Android only works with Java 1.6. It doesn't work with 1.7, Dalvic won't support it. So you can't use 1.7 features.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

I have solved my problem.

It turned out the error was ALSO related to a change I made in the res/values-v14 file which would resolve a performance issue (drawing background twice), but it only created a much larger problem. I added these sentenses to <style>:

<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@null</item>

When I deleted these sentences AND reset the target Java version from 1.7 to 1.6 my problem was gone. Why this solved my problem or why this gave the error in the first place is still a mystery to me.

Rob
  • 51
  • 11