0

I'm using json-simple library for working with json. I have migrated from Eclipse to AndroidStudio and few parts of code began marks as error. But still project builds normally.

import org.json.simple.JSONArray;

public void addParam(String[] params) {
    JSONArray json = new JSONArray();
    for (int i = 0, l = params.length; i < l; ++i) {
        //In next line part "params[i]" AndroidStudio underlined with red
        json.add(params[i]);
    }
    mParamsString += json.toJSONString();
}

When I'm moving cursor over this line there is error message:
add(E) in ArrayList cannot be applied to java.lang.String

So if everything was fine in Eclipse and project compiles normally I think something wrong with AndroidStudio. How to remove this error, beacause of this error whole project marked as it contains error, it's very annoying

cooperok
  • 4,249
  • 3
  • 30
  • 48

1 Answers1

0

first of all no add() method for JSONArray class use put() instead

and other thing ..check the JSONArray is from import org.json.JSONObject;

public void addParam(String[] params) {
JSONArray json = new JSONArray();
for (int i = 0, l = params.length; i < l; ++i) {
    //In next line part "params[i]" AndroidStudio underlined with red
    json.put(params[i]);
    }
    mParamsString += json.toJSONString();
}
Angad Tiwari
  • 1,738
  • 1
  • 12
  • 23
  • yes... put() method belong to org.json.JSONObject as well as optString(String) ... i'm pretty sure ..there is no add() method for this class – Angad Tiwari Jun 03 '15 at 13:08
  • I'm using org.json.simple.JSONArray. Classes from regular org.json doesn't provide enough functionality. They incorrectly converts to string arrays with objects, and objects with array values – cooperok Jun 03 '15 at 13:47