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

  • SEARCH
  • Home
  • 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 5844103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:14:47+00:00 2026-05-22T12:14:47+00:00

I have written android class which will call RESTful web service. If request is

  • 0

I have written android class which will call RESTful web service. If request is successful,
response will be JSON object. I write android class like this:

public class android extends Activity {

    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView txt = (TextView) findViewById(R.id.textView1);
    txt.setText(getInputStreamFromUrl("http://localhost:8080/kyaw"));
    }

    public static String getInputStreamFromUrl(String url) {
          InputStream content = null;
          try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response = httpclient.execute(new HttpGet(url));
            content = response.getEntity().getContent();
          } catch (Exception e) {
            Log.e("[GET REQUEST]", "Network exception");
          }
            String result=convert(content);
            return result;
        }

    private static String convert(InputStream in)
    {
        BufferedReader reader=new BufferedReader(new InputStreamReader(in));
        StringBuilder sb=new StringBuilder();
        String line=null;
        try{
            while((line=reader.readLine())!=null){
                sb.append(line+"\n");
            }
        }catch(Exception e)
        {
            e.printStackTrace();
        }finally{
            try{
                in.close();
            }catch(IOException e){
                e.printStackTrace();
            }
        }
        return sb.toString();
    }

}

I have a problem after i run.I will get exception coz i return as a string.But response is JSON .How should I convert JSON to String or other way and then how to show result in android screen?

thanksenter image description here

  • 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-05-22T12:14:47+00:00Added an answer on May 22, 2026 at 12:14 pm

    well “http://localhost:8080/kyaw” is a problem … by this you poining to emulator not emulator’s host … and you getting network error

    try “http://ip.of.your.host:8080/kyaw”

    EDIT:

            content = response.getEntity().getContent();// here comes an error
          } catch (Exception e) {
            Log.e("[GET REQUEST]", "Network exception");//we catch it here
          }
          //here you got content == null
          //so you getting null point exception 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to web services. I have written a rest web service which
I have written an AppleScript which when supplied with a Windows network link, will
I have written an android app which listens to the phone signal strength using
I have written a simple Android application that uses a sqlite database which is
I have written a piece of Java code which is intended as to call
I have written REST web service in netbean IDE using jersey framework and java.
I have written an android service, that I need to run in the background
I have written an application in C which I am porting to Android using
In the Android application I have written, there is a portion which allows the
I have written a custom preference class which contains a simple progress bar in

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.