1

Hi Android Developers,

I have a problem with string splitting in android in tells that change the java compliance to JRE 1.7 when i changed the compliance error occurs because it works only in api level 19

   String st="a,b,c,d";
   String[] temp=st.split(",");
   for(int i=0;i<temp.lenght;i++)
   {
       switch(temp[i])
       {
           case "a":
                   //print something
                   break;
           case "b":
                  //print something
                  break;
           case "c":
                 //print something
                  break;
           case "d":
                 //print something
                 break;
          default:
                 //print something
       }
   }

The error is in the switch statement, how can I solve it I am developing in 2.3 devices?

The error:

[2014-08-22 11:47:26 - text] Using 1.7 requires compiling with Android 4.4 (KitKat); currently using API 8
6
  • 1
    possible duplicate of switch for type string for java 1.6 Commented Aug 22, 2014 at 6:12
  • 1
    Switching strings is implemented in Java 1.7+ For the API lvl 19 error - i don't see here any Android specific code. Commented Aug 22, 2014 at 6:13
  • 2
    Just replace your switch statement with set of else-if statements Switch by String was introduced in JDK 1.7 while Android SDK based on JDK 1.6 Commented Aug 22, 2014 at 6:15
  • You haven't defined anything in the default case. Commented Aug 22, 2014 at 6:15
  • 1.6 doesn't allow you to pass strings in switch statement. Please change it. Commented Aug 22, 2014 at 6:18

3 Answers 3

3

To resolve: Using 1.7 requires compiling with Android 4.4 (KitKat); currently using API 8

  1. Try Project --> Properties --> Java Compiler --> Compliance Level --> 1.6

    Using 1.7 requires compiling with Android 4.4 (KitKat); currently using API 8

  2. After setting compliance level, clean the project. If required, restart eclipse.

Also, as James pointed out, your for loop should be i<temp.length (Spelling mistake should be corrected)

Sign up to request clarification or add additional context in comments.

1 Comment

@Ribin. Thank you for accepting as answer. Please also upvote since it would increase our tag scores. TIA!
2

You have made a spelling error:

for(int i=0;i<temp.lenght;i++)
                    ^^

It should say length not lenght

1 Comment

That's a problem, but not the problem in question.
0

The Compiler compliance level is Version Dependent in eclipse. If you are using Eclipse 3.7 or lower then you won't get 1.7 compliance. Use Eclipse JUNO or higher.

For more on JDT Core 7 and its release related information

UPDATE:

Even eclipse 3.7.1 version supports Java 7 features and compliance level.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.