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 8350825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:26:25+00:00 2026-06-09T08:26:25+00:00

I am trying to parse a JSON string in java to have the individual

  • 0

I am trying to parse a JSON string in java to have the individual value printed separately. But while making the program run I get the following error-

Exception in thread "main" java.lang.RuntimeException: Stub!
       at org.json.JSONObject.<init>(JSONObject.java:7)
       at ShowActivity.main(ShowActivity.java:29)

My Class looks like-

import org.json.JSONException;
import org.json.JSONObject;

public class ShowActivity {
   private final static String  jString = "{" 
   + "    \"geodata\": [" 
   + "        {" 
   + "                \"id\": \"1\"," 
   + "                \"name\": \"Julie Sherman\","                  
   + "                \"gender\" : \"female\"," 
   + "                \"latitude\" : \"37.33774833333334\"," 
   + "                \"longitude\" : \"-121.88670166666667\""            
   + "                }" 
   + "        }," 
   + "        {" 
   + "                \"id\": \"2\"," 
   + "                \"name\": \"Johnny Depp\","          
   + "                \"gender\" : \"male\"," 
   + "                \"latitude\" : \"37.336453\"," 
   + "                \"longitude\" : \"-121.884985\""            
   + "                }" 
   + "        }" 
   + "    ]" 
   + "}"; 
   private static JSONObject jObject = null;

   public static void main(String[] args) throws JSONException {
       jObject = new JSONObject(jString);
       JSONObject geoObject = jObject.getJSONObject("geodata");

       String geoId = geoObject.getString("id");
           System.out.println(geoId);

       String name = geoObject.getString("name");
       System.out.println(name);

       String gender=geoObject.getString("gender");
       System.out.println(gender);

       String lat=geoObject.getString("latitude");
       System.out.println(lat);

       String longit =geoObject.getString("longitude");
       System.out.println(longit);                   
   }
}

Let me know what is it I am missing, or the reason why I do get that error everytime I run the application. Any comments would be appreciated.

  • 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-09T08:26:26+00:00Added an answer on June 9, 2026 at 8:26 am

    See my comment.
    You need to include the full org.json library when running as android.jar only contains stubs to compile against.

    In addition, you must remove the two instances of extra } in your JSON data following longitude.

       private final static String JSON_DATA =
         "{" 
       + "  \"geodata\": [" 
       + "    {" 
       + "      \"id\": \"1\"," 
       + "      \"name\": \"Julie Sherman\","                  
       + "      \"gender\" : \"female\"," 
       + "      \"latitude\" : \"37.33774833333334\"," 
       + "      \"longitude\" : \"-121.88670166666667\""
       + "    }," 
       + "    {" 
       + "      \"id\": \"2\"," 
       + "      \"name\": \"Johnny Depp\","          
       + "      \"gender\" : \"male\"," 
       + "      \"latitude\" : \"37.336453\"," 
       + "      \"longitude\" : \"-121.884985\""
       + "    }" 
       + "  ]" 
       + "}"; 
    

    Apart from that, geodata is in fact not a JSONObject but a JSONArray.

    Here is the fully working and tested corrected code:

    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    public class ShowActivity {
    
    
      private final static String JSON_DATA =
         "{" 
       + "  \"geodata\": [" 
       + "    {" 
       + "      \"id\": \"1\"," 
       + "      \"name\": \"Julie Sherman\","                  
       + "      \"gender\" : \"female\"," 
       + "      \"latitude\" : \"37.33774833333334\"," 
       + "      \"longitude\" : \"-121.88670166666667\""
       + "    }," 
       + "    {" 
       + "      \"id\": \"2\"," 
       + "      \"name\": \"Johnny Depp\","          
       + "      \"gender\" : \"male\"," 
       + "      \"latitude\" : \"37.336453\"," 
       + "      \"longitude\" : \"-121.884985\""
       + "    }" 
       + "  ]" 
       + "}"; 
    
      public static void main(final String[] argv) throws JSONException {
        final JSONObject obj = new JSONObject(JSON_DATA);
        final JSONArray geodata = obj.getJSONArray("geodata");
        final int n = geodata.length();
        for (int i = 0; i < n; ++i) {
          final JSONObject person = geodata.getJSONObject(i);
          System.out.println(person.getInt("id"));
          System.out.println(person.getString("name"));
          System.out.println(person.getString("gender"));
          System.out.println(person.getDouble("latitude"));
          System.out.println(person.getDouble("longitude"));
        }
      }
    }
    

    Here’s the output:

    C:\dev\scrap>java -cp json.jar;. ShowActivity
    1
    Julie Sherman
    female
    37.33774833333334
    -121.88670166666667
    2
    Johnny Depp
    male
    37.336453
    -121.884985
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse a JSON string in Java but I cant figure out
I'm trying to parse this string into java, but I keep getting errors. {id:1,jsonrpc:2.0,result:{limits:{end:3,start:0,total:3},sources:[{file:/media/storage/media/re
I have been trying to parse Json into A ListView but when i do
I'm trying to parse a simple JSON string, but I'm not used to do
I was trying to parse a JSON string from USGS . However I get
I;m trying to parse a json string which I receive from web server as
I am trying to parse the following JSON string remotely: [{name:Object1,data:[1,2]},{name:Object2,data:[3,4]}] I am doing
I am trying to parse a string which in JSON format only that keys
I am trying to parse some JSON. I've passed a constant key value and
Im trying to parse an JSON response string to my class objects.. I can't

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.