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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:26:11+00:00 2026-06-01T08:26:11+00:00

I am trying to access my json data name on jsp page from android

  • 0

I am trying to access my json data “name” on jsp page from android app.. I am getting error and the application get force closed.

my jsp code is as follows…

<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="org.json.simple.JSONObject"%>
<%
JSONObject obj=new JSONObject();
obj.put("name","foo");
obj.put("num",new Integer(100));
obj.put("balance",new Double(1000.21));
obj.put("is_vip",new Boolean(true));
obj.put("nickname",null);
out.print(obj);
out.flush();
%>

my android java code is as follows…

package com.campuspro.start;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class JsonDemo extends Activity 
{
TextView tv=(TextView)findViewById(R.id.jsonresult);
HttpClient client=new DefaultHttpClient();
String url="http://10.0.2.2:7001/f/json.jsp";

@Override
protected void onCreate(Bundle savedInstanceState) {

    // TODO Auto-generated method stub
    try{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.result_json);
    HttpGet get=new HttpGet(url);
    HttpResponse r=client.execute(get);
    int status=r.getStatusLine().getStatusCode();
    if(status==200)
    {
        HttpEntity e=r.getEntity();
        String data=EntityUtils.toString(e);
        JSONArray arr=new JSONArray(data);
        JSONObject last=arr.getJSONObject(0);
        String result=last.getString("name");
        tv.setText(result);
    }

}catch(Exception e)
{

}
}

}

my log cat error on eclipse is…

04-04 09:30:53.910: D/AndroidRuntime(345): Shutting down VM
04-04 09:30:53.910: W/dalvikvm(345): threadid=1: thread exiting with uncaught exception           (group=0x4001d800)
04-04 09:30:54.190: E/AndroidRuntime(345): FATAL EXCEPTION: main
04-04 09:30:54.190: E/AndroidRuntime(345): java.lang.RuntimeException: Unable to   instantiate activity ComponentInfo{com.campuspro.start/com.campuspro.start.JsonDemo}:   java.lang.NullPointerException
04-04 09:30:54.190: E/AndroidRuntime(345):  at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-04 09:30:54.190: E/AndroidRuntime(345):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-04 09:30:54.190: E/AndroidRuntime(345):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-04 09:30:54.190: E/AndroidRuntime(345):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-04 09:30:54.190: E/AndroidRuntime(345):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 09:30:54.190: E/AndroidRuntime(345):  at android.os.Looper.loop(Looper.java:123)
04-04 09:30:54.190: E/AndroidRuntime(345):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-04 09:30:54.190: E/AndroidRuntime(345):  at java.lang.reflect.Method.invokeNative(Native Method)
04-04 09:30:54.190: E/AndroidRuntime(345):  at java.lang.reflect.Method.invoke(Method.java:521)
04-04 09:30:54.190: E/AndroidRuntime(345):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-04 09:30:54.190: E/AndroidRuntime(345):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-04 09:30:54.190: E/AndroidRuntime(345):  at dalvik.system.NativeStart.main(Native Method)
04-04 09:30:54.190: E/AndroidRuntime(345): Caused by: java.lang.NullPointerException
04-04 09:30:54.190: E/AndroidRuntime(345):  at android.app.Activity.findViewById(Activity.java:1637)
04-04 09:30:54.190: E/AndroidRuntime(345):  at com.campuspro.start.JsonDemo.<init>(JsonDemo.java:18)
04-04 09:30:54.190: E/AndroidRuntime(345):  at java.lang.Class.newInstanceImpl(Native Method)
04-04 09:30:54.190: E/AndroidRuntime(345):  at java.lang.Class.newInstance(Class.java:1429)
04-04 09:30:54.190: E/AndroidRuntime(345):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-04 09:30:54.190: E/AndroidRuntime(345):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-04 09:30:54.190: E/AndroidRuntime(345):  ... 11 more
  • 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-01T08:26:13+00:00Added an answer on June 1, 2026 at 8:26 am

    You have error in

    TextView tv=(TextView)findViewById(R.id.jsonresult);
    

    You should set it up after setContentView(R.layout.result_json);

    • 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 json data from google directions but can't seem to access
I'm trying to get some json data from a remote website. I run my
I'm trying to get JSON data from facebook using the following code: var getFriends
I'm new to JSON and ajax, but i'm trying to access data in an
I have been having some issues retrieving JSON data from a WCF service application
I am trying to parse FB comments JSON, which I get from var url
I'm trying to get JSON data to turn it into html but the JSON
I'm trying to learn how to use CURL and Json to access data sent
I'm trying to parse returned json but can't access the data. Trying to access
I was trying to retrieve some JSON data from Google's AppEngine, and also a

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.