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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:07:37+00:00 2026-05-31T00:07:37+00:00

this line is in onCreate function JSONObject cat = getJSONfromURL(http://localhost/2010/hkinterview/index.php?op=androidCat); The following code is

  • 0

this line is in onCreate function

JSONObject cat = getJSONfromURL("http://localhost/2010/hkinterview/index.php?op=androidCat");

The following code is the method which i found on web which parsing the json data from URL

    public static JSONObject getJSONfromURL(String url){

    //initialize
    InputStream is = null;   
    String result = "";   
    JSONObject jArray = null;

    //http post
    try {

        HttpClient httpclient = new DefaultHttpClient();   
        HttpPost httppost = new HttpPost(url);    
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();

        is = entity.getContent();    

    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection "+e.toString());   
    }
    //convert response to string

    try {

        BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);  
        StringBuilder sb = new StringBuilder();   
        String line = null;

        while ((line = reader.readLine()) != null) {   
            sb.append(line + "\n");
        }

        is.close();
        result=sb.toString();

    } catch (Exception e) {    
        Log.e("log_tag", "Error converting result "+e.toString());
    }
    //try parse the string to a JSON object

    try {
        jArray = new JSONObject(result);

    } catch (JSONException e) {
        Log.e("log_tag", "Error parsing data "+e.toString());

    }
    return jArray;
}

The data output from the php

[{"cid":"1","cname":"\u6703\u8a08\u754c Accounting ","img_cname":"nil"},{"cid":"2","cname":"\u5ee3\u544a\u754c Advertising","img_cname":"nil"},{"cid":"3","cname":"\u9280\u884c\u754c Banking ","img_cname":"nil"},{"cid":"4","cname":"\u653f\u5e9c\u670d\u52d9\u754c Civil Serv","img_cname":"nil"},{"cid":"5","cname":"\u5efa\u7bc9\u754c Construction","img_cname":"nil"},{"cid":"6","cname":"\u5ba2\u6236\u670d\u52d9\u696d CS ","img_cname":"nil"},{"cid":"7","cname":"\u8a2d\u8a08\u696d Design","img_cname":"nil"},{"cid":"8","cname":"\u6559\u80b2\u754c","img_cname":"nil"},{"cid":"9","cname":"\u5de5\u7a0b\u754c Engineering","img_cname":"nil"},{"cid":"10","cname":"\u98f2\u98df\u754c F&B ","img_cname":"nil"},{"cid":"11","cname":"\u9152\u5e97\u754c Hotel ","img_cname":"nil"},{"cid":"12","cname":"\u4fdd\u96aa\u754c Insurance ","img_cname":"nil"},{"cid":"13","cname":"\u6295\u8cc7\u754c Investment ","img_cname":"nil"},{"cid":"14","cname":"\u6cd5\u5f8b\u754c Law ","img_cname":"nil"},{"cid":"15","cname":"\u65b0\u805e\u50b3\u64ad\u754c Media","img_cname":"nil"},{"cid":"16","cname":"\u91ab\u7642\u5065\u5eb7\u754c Medicine\/Health","img_cname":"nil"},{"cid":"17","cname":"\u63a1\u8cfc\u754c Merchandising ","img_cname":"nil"},{"cid":"18","cname":"\u5730\u7522\u754c Property","img_cname":"nil"},{"cid":"19","cname":"\u96f6\u552e\u98f2\u98df Retail & R","img_cname":"nil"},{"cid":"20","cname":"\u92b7\u552e\u53ca\u5e02\u5834\u754c S & M","img_cname":"nil"},{"cid":"21","cname":"\u793e\u798f\u754c Social Services","img_cname":"nil"},{"cid":"22","cname":"\u96fb\u8a0a\u754c Telecom","img_cname":"nil"},{"cid":"23","cname":"\u65c5\u904a\u696d Tourism","img_cname":"nil"},{"cid":"24","cname":"\u5176\u4ed6 others","img_cname":"nil"},{"cid":"25","cname":"\u7269\u6d41\u754c Logistics","img_cname":"nil"},{"cid":"26","cname":"\u8cc7\u8a0a\u79d1\u6280\u754c I.T.","img_cname":"nil"}]

the Errors

03-06 12:58:02.574: E/log_tag(1776): Error in http connection java.net.SocketException: Permission denied
03-06 12:58:02.574: E/log_tag(1776): Error converting result java.lang.NullPointerException
03-06 12:58:02.584: E/log_tag(1776): Error parsing data org.json.JSONException: End of input at character 0 of 

the code seems it can’t connect the url, any ideas?

updated:
after i added <uses-permission android:name="android.permission.INTERNET" />

03-06 13:14:23.444: E/log_tag(1923): Error in http connection org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused
03-06 13:14:23.444: E/log_tag(1923): Error converting result java.lang.NullPointerException
03-06 13:14:23.454: E/log_tag(1923): Error parsing data org.json.JSONException: End of input at character 0 of 
03-06 13:14:23.454: D/AndroidRuntime(1923): Shutting down VM
03-06 13:14:23.454: W/dalvikvm(1923): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-06 13:14:23.464: E/AndroidRuntime(1923): FATAL EXCEPTION: main
03-06 13:14:23.464: E/AndroidRuntime(1923): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.me.hkinterview/com.me.hkinterview.hkinterviewActivity}: java.lang.NullPointerException
03-06 13:14:23.464: E/AndroidRuntime(1923):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at android.os.Looper.loop(Looper.java:123)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at android.app.ActivityThread.main(ActivityThread.java:3683)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at java.lang.reflect.Method.invokeNative(Native Method)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at java.lang.reflect.Method.invoke(Method.java:507)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at dalvik.system.NativeStart.main(Native Method)
03-06 13:14:23.464: E/AndroidRuntime(1923): Caused by: java.lang.NullPointerException
03-06 13:14:23.464: E/AndroidRuntime(1923):     at com.me.hkinterview.hkinterviewActivity.onCreate(hkinterviewActivity.java:27)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-06 13:14:23.464: E/AndroidRuntime(1923):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-06 13:14:23.464: E/AndroidRuntime(1923):     ... 11 more

And i added real domain name

03-06 13:27:36.024: E/log_tag(2021): Error parsing data org.json.JSONException: Value [{"img_cname":"nil","cid":"1","cname":"會計界 Accounting "},{"img_cname":"nil","cid":"2","cname":"廣告界 Advertising"},{"img_cname":"nil","cid":"3","cname":"銀行界 Banking "},{"img_cname":"nil","cid":"4","cname":"政府服務界 Civil Serv"},{"img_cname":"nil","cid":"5","cname":"建築界 Construction"},{"img_cname":"nil","cid":"6","cname":"客戶服務業 CS "},{"img_cname":"nil","cid":"7","cname":"設計業 Design"},{"img_cname":"nil","cid":"8","cname":"教育界"},{"img_cname":"nil","cid":"9","cname":"工程界 Engineering"},{"img_cname":"nil","cid":"10","cname":"飲食界 F&B "},{"img_cname":"nil","cid":"11","cname":"酒店界 Hotel "},{"img_cname":"nil","cid":"12","cname":"保險界 Insurance "},{"img_cname":"nil","cid":"13","cname":"投資界 Investment "},{"img_cname":"nil","cid":"14","cname":"法律界 Law "},{"img_cname":"nil","cid":"15","cname":"新聞傳播界 Media"},{"img_cname":"nil","cid":"16","cname":"醫療健康界 Medicine\/Health"},{"img_cname":"nil","cid":"17","cname":"採購界 Merchandising "},{"img_cname":"nil","cid":"18","cname":"地產界 Property"},{"img_cname":"nil","cid":"19","cname":"零售飲食 Retail & R"},{"img_cname":"nil","cid":"20","cname":"銷售及市場界 S & M"},{"img_cname":"nil","cid":"21","cname":"社福界 Social Services"},{"img_cname":"nil","cid":"22","cname":"電訊界 Telecom"},{"img_cname":"nil","cid":"23","cname":"旅遊業 Tourism"},{"img_cname":"nil","cid":"24","cname":"其他 others"},{"img_cname":"nil","cid":"25","cname":"物流界 Logistics"},{"img_cname":"nil","cid":"26","cname":"資訊科技界 I.T."}] of type org.json.JSONArray cannot be converted to JSONObject
03-06 13:27:36.024: D/AndroidRuntime(2021): Shutting down VM
03-06 13:27:36.024: W/dalvikvm(2021): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-06 13:27:36.034: E/AndroidRuntime(2021): FATAL EXCEPTION: main
03-06 13:27:36.034: E/AndroidRuntime(2021): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.me.hkinterview/com.me.hkinterview.hkinterviewActivity}: java.lang.NullPointerException
03-06 13:27:36.034: E/AndroidRuntime(2021):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at android.os.Looper.loop(Looper.java:123)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at android.app.ActivityThread.main(ActivityThread.java:3683)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at java.lang.reflect.Method.invokeNative(Native Method)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at java.lang.reflect.Method.invoke(Method.java:507)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at dalvik.system.NativeStart.main(Native Method)
03-06 13:27:36.034: E/AndroidRuntime(2021): Caused by: java.lang.NullPointerException
03-06 13:27:36.034: E/AndroidRuntime(2021):     at com.me.hkinterview.hkinterviewActivity.onCreate(hkinterviewActivity.java:27)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-06 13:27:36.034: E/AndroidRuntime(2021):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-06 13:27:36.034: E/AndroidRuntime(2021):     ... 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-05-31T00:07:38+00:00Added an answer on May 31, 2026 at 12:07 am

    for the exception connection org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused
    see this
    error connection refused

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code generates this error message at the public void onClick line. Multiple
This line in YUI's Reset CSS is causing trouble for me: address,caption,cite,code,dfn,em,strong,th,var { font-style:
This line of code ((Matches)Container.DataItem).MatchID works in C# but in VB.NET, when used in
this line of the code makes the form see-through User32Wrappers.SetLayeredWindowAttributes(Me.Handle, 0, _ 255 *
This line is giving error: Too few arguments. What is the problem? $InsertQuery =
Given this line of code in C: printf(%3.0f\t%6.1f\n, fahr, ( (5.0/9.0) * (fahr-32) )
Consider this line: std::wcout << Hello World!; Is it OK to pass char* or
Having this line Cursor c = db.rawQuery(PRAGMA table_info(?), new String[] {tableName}); and getting this:
Got this line of code here but its not working. private void Button_Click(object sender,
I have this line in a javascript block in a page: res = foo('<%=

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.