0

I have an issue where I am using import org.json.JSONObject; and using the constructor new JSONObject(Object) which in this case is an inputstream.

Eclipse has no issue with this, but AndroidStudio/IntelliJ only tells me that "constructor JSONObject(inputstream) does not exist`. And when I open the declaration of org.json.JSONObject in Android Studio, I do not see JSONObject(Object) constructor, yet this simply exists when used in Eclipse.

How to fix for Android Studio?

insight appreciated....

CQM
  • 42,592
  • 75
  • 224
  • 366

2 Answers2

1

Try this in both Intellij IDEA and Android Studio.

File > Invalidate Caches / Restart

Androiderson
  • 16,865
  • 6
  • 62
  • 72
0

That constructor does not show up in Android reference: http://developer.android.com/reference/org/json/JSONObject.html

Are you sure you are using the default Android JSONObject class in Eclipse and not including an alternative library?

BVB
  • 5,380
  • 8
  • 41
  • 62
  • yes, I have also added the apache json into the project, but I feel like Android Studio is ignoring it – CQM Sep 20 '13 at 21:18
  • Ah, yes, it might be. Did you update your build.gradle file to use the new Jar? Also, did you add the Jar as a library in the Project Structure settings? Here's how to do it: http://stackoverflow.com/a/16628496/379245 – BVB Sep 20 '13 at 21:19
  • I'm not exactly sure how to do that, the jar was already in my project when I started (migrated from eclipse) – CQM Sep 20 '13 at 21:47
  • Check out the link in my comment above. Find the Jar file in your project structure, then make sure that build.gradle includes it within the dependencies tag. Also, right click on that jar and select `Add as Library`. See here for more information about Gradle: http://www.gradleware.com/resources/tech/android – BVB Sep 20 '13 at 21:52
  • I have `compile fileTree(dir: 'libs', include: '*.jar')` in my script – CQM Sep 20 '13 at 21:56
  • Is your json jar in the libs directory under your project (libs directory should be in the same directory as the src directory). Also, did you right click on it and add it as a library? – BVB Sep 20 '13 at 21:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/37758/discussion-between-bvb-and-cqm) – BVB Sep 20 '13 at 22:04