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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:38:45+00:00 2026-06-19T00:38:45+00:00

in my project JSONObject and JSONArray data work in level 8 and level 10

  • 0

in my project JSONObject and JSONArray data work in level 8 and level 10 but same code not working level 16 why this happen here is my code

  HttpClient httpclient = new DefaultHttpClient();

    HttpGet httpget = new HttpGet(url);
    HttpResponse response;
    try {
        response = httpclient.execute(httpget);
        Log.i("response", "response" + response);
        HttpEntity entity = response.getEntity();
        Log.i("entity", "entity" + entity);

        if (entity != null) {

            InputStream instream = entity.getContent();
            String result = convertStreamToString(instream);
            JSONObject json = new JSONObject(result);

            JSONObject jsonOnb = json.getJSONObject("query").getJSONObject("pages") ;
            JSONObject pagesObj = jsonOnb.getJSONObject(jsonOnb.names().getString(0));          

            Log.i("pageid", "pageid= " +pagesObj.get("pageid"));                   
            Log.i("title", "title= " +pagesObj.get("title"));  
            instream.close();
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

this code working in level 8 and 10 but not working level 16 facing this errors in level 16

02-18 16:00:22.480: D/AndroidRuntime(605): Shutting down VM
02-18 16:00:22.480: W/dalvikvm(605): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
02-18 16:00:22.500: E/AndroidRuntime(605): FATAL EXCEPTION: main
02-18 16:00:22.500: E/AndroidRuntime(605): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.a/com.example.a.MainActivity}: android.os.NetworkOnMainThreadException
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.os.Looper.loop(Looper.java:137)
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.app.ActivityThread.main(ActivityThread.java:4745)
02-18 16:00:22.500: E/AndroidRuntime(605):  at java.lang.reflect.Method.invokeNative(Native Method)
02-18 16:00:22.500: E/AndroidRuntime(605):  at java.lang.reflect.Method.invoke(Method.java:511)
02-18 16:00:22.500: E/AndroidRuntime(605):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-18 16:00:22.500: E/AndroidRuntime(605):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-18 16:00:22.500: E/AndroidRuntime(605):  at dalvik.system.NativeStart.main(Native Method)
02-18 16:00:22.500: E/AndroidRuntime(605): Caused by: android.os.NetworkOnMainThreadException
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
02-18 16:00:22.500: E/AndroidRuntime(605):  at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
02-18 16:00:22.500: E/AndroidRuntime(605):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
02-18 16:00:22.500: E/AndroidRuntime(605):  at java.net.InetAddress.getAllByName(InetAddress.java:214)
02-18 16:00:22.500: E/AndroidRuntime(605):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
02-18 16:00:22.500: E/AndroidRuntime(605):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
02-18 16:00:22.500: E/AndroidRuntime(605):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
02-18 16:00:22.500: E/AndroidRuntime(605):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
02-18 16:00:22.500: E/AndroidRuntime(605):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-18 16:00:22.500: E/AndroidRuntime(605):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-18 16:00:22.500: E/AndroidRuntime(605):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-18 16:00:22.500: E/AndroidRuntime(605):  at com.example.a.MainActivity.onCreate(MainActivity.java:41)
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.app.Activity.performCreate(Activity.java:5008)
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-18 16:00:22.500: E/AndroidRuntime(605):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
02-18 16:00:22.500: E/AndroidRuntime(605):  ... 11 more


line 41 is
response = httpclient.execute(httpget);`

  • 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-19T00:38:46+00:00Added an answer on June 19, 2026 at 12:38 am

    You need to add these two line of code on your onCreate() function

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    
    StrictMode.setThreadPolicy(policy); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This project was coped almost exacatly from the example on the admob page but
I'm trying to work on a new project parsing some JSON data for a
everyone i have a problem with my project here is my search.java code import
I'm not familiar with PHP and JSON but need it for my Android project.
I've been going through two tutorials to get the code for this project of
I'm using GSON for a project. In particular I use this code to generate
Now i am working with an android project here I've a list view that
I am working on mvc project in razor.In this i am working on import
I have this java project and I'm not using an IDE. What do I
Hello i've build already smartphone apps but now i'm starting working on a project

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.