Ribin Haridas
Ribin Haridas

Reputation: 1620

String Splitting Error In Android

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

Upvotes: 1

Views: 1273

Answers (3)

Nirav Mehta
Nirav Mehta

Reputation: 1755

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.

Upvotes: 0

ngrashia
ngrashia

Reputation: 9904

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)

Upvotes: 3

James
James

Reputation: 338

You have made a spelling error:

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

It should say length not lenght

Upvotes: 2

Related Questions