Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8748775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:35:02+00:00 2026-06-13T12:35:02+00:00

Fixed the link, now I get a JSON error msg java.lang.ClassCastException: org.json.JSONObject$1 cannot be

  • 0

Fixed the link, now I get a JSON error msg

 java.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to org.json.JSONObject

Apparently my error lies somewhere here:

String response     = streamToString(urlConnection.getInputStream());
        JSONObject jsonObj  = (JSONObject) new JSONTokener(response).nextValue();             
        JSONArray groups    = (JSONArray) jsonObj.getJSONObject("response").getJSONArray("groups");

        int length          = groups.length();
        if (length > 0) {                
            for (int i = 0; i < length; i++) {                    
                JSONObject group    = (JSONObject) groups.get(i);                    
                JSONArray items     = (JSONArray) group.getJSONArray("items");                     
                int ilength         = items.length();                     
                for (int j = 0; j < ilength; j++) {                        
                    JSONObject item = (JSONObject) items.get(j);                         
                    FsqVenue venue  = new FsqVenue();                         
                    venue.id        = item.getString("id");                        
                    venue.name      = item.getString("name");                         
                    JSONObject location = (JSONObject) item.getJSONObject("location");                         
                    Location loc    = new Location(LocationManager.GPS_PROVIDER);                         
                    loc.setLatitude(Double.valueOf(location.getString("lat")));                        
                    loc.setLongitude(Double.valueOf(location.getString("lng")));                         
                    venue.location  = loc;                        
                    venue.address   = location.getString("address");                        
                    venue.distance  = location.getInt("distance");                        
                    venue.type      = group.getString("type");                         
                    VenueList.add(venue);
                    }

tomcat message

10-25 16:37:32.731: I/System.out(12828): https://api.foursquare.com/v2/venues/search?            ll=2.94,101.66&client_id=xxxxx&client_secret=xxxxxxx


10-25 16:37:32.731: D/FoursquareApi(12828): OPening URLhttps://api.foursquare.com/v2/venues/search?ll=2.94,101.66&client_id=xxxxxxx&client_secret=xxxxxxx
10-25 16:37:34.645: W/System.err(12828): java.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to org.json.JSONObject
10-25 16:37:34.645: W/System.err(12828):    at com.example.reddot.Foursquare.getNearby(Foursquare.java:57)
10-25 16:37:34.653: W/System.err(12828):    at com.example.reddot.MainActivity$LoadPlaces.doInBackground(MainActivity.java:466)
10-25 16:37:34.653: W/System.err(12828):    at com.example.reddot.MainActivity$LoadPlaces.doInBackground(MainActivity.java:1)
10-25 16:37:34.653: W/System.err(12828):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-25 16:37:34.653: W/System.err(12828):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-25 16:37:34.653: W/System.err(12828):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-25 16:37:34.661: W/System.err(12828):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-25 16:37:34.661: W/System.err(12828):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-25 16:37:34.661: W/System.err(12828):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-25 16:37:34.661: W/System.err(12828):    at java.lang.Thread.run(Thread.java:856)
10-25 16:37:34.661: I/System.out(12828): errorjava.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to org.json.JSONObject
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:35:03+00:00Added an answer on June 13, 2026 at 12:35 pm

    using url connection() returns an empty result as such json will not be able to phrase empty data. the alternative to this is to use googleclient Api as follows

            HttpTransport transport = new NetHttpTransport();
            HttpRequestFactory httpRequestFactory = createRequestFactory   (HTTP_TRANSPORT);
            String ll = String.valueOf(df.format(lonlat))+","+String.valueOf(df.format(lonlat2));
            url = (API_URL+ "venues/search?ll="+ll+"&client_id="+CLIENT_ID+"&client_secret="+CLIENT_SECRET+"&v"+v); 
            HttpRequest request = httpRequestFactory
                    .buildGetRequest(new GenericUrl(url));
    
    
            System.out.println(request);
            HttpResponse httpResponse = request.execute();
    
            JSONObject object = new JSONObject(httpResponse.parseAsString());
            JSONObject foursquareResponse = (JSONObject) object.get("response");
            JSONArray groups    = (JSONArray) foursquareResponse.get("groups");
            JSONObject group = (JSONObject)groups.get(0);
            JSONArray items = (JSONArray)group.get("items");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PROBLEM FIXED FOR NOW. I fixed it by deleting my javascript section for a
According to this link, now we can use Request.Unvalidated to access a raw value
When i use @try @catch, i get error: expected identifier or '(' before 'try'
I got a centered website with a fixed width. Now, I want to add
Note: This code works now. I have fixed some stupid mistake and I have
Right now we have a web page with a bunch of link sections on
FIXED! The problem was I didn't know you had to initialize a connection to
How do people switch fixed elements when scrolling down the page? Here's a perfect
I have a centred fixed width content div , and if there isnt enough
I have a fixed data which will be used in a UITableView later and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.