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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:27:18+00:00 2026-06-17T22:27:18+00:00

I am having a script force close only when i debug on higher API

  • 0

I am having a script force close only when i debug on higher API : 16 , But it is working fine when it come to an API : 10. Could it be my project setup problem?

It is a simple request to a server to get list of category in a fragment.

gallery.java

public class gallery extends Fragment {

    JSONArray jArray;
    String result = null;
    InputStream is = null;
    StringBuilder sb = null;
    private ListView storeList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View myFragmentView = inflater.inflate(R.layout.tab_frag1_layout,
                container, false);
        storeList = (ListView) inflater.inflate(R.layout.list, null);
        return myFragmentView;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        // http post
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(
                    "http://xxx.xxx.xxx/android_link.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            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);
            sb = new StringBuilder();
            sb.append(reader.readLine() + "\n");

            String line = "0";
            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());
        }
        // paring data
        int ct_id;
        String ct_name;
        try {
            jArray = new JSONArray(result);
            JSONObject json_data = null;
            for (int i = 0; i < jArray.length(); i++) {
                json_data = jArray.getJSONObject(i);
                ct_id = json_data.getInt("brand_id");
                ct_name = json_data.getString("series_name");

            }
        } catch (JSONException e1) {
            Toast.makeText(getActivity(), "No Data Found", Toast.LENGTH_LONG)
                    .show();
        } catch (ParseException e1) {
            e1.printStackTrace();
        }
    }

log.txt

01-29 03:25:54.653: E/log_tag(4324): Error in http connectionandroid.os.NetworkOnMainThreadException
01-29 03:25:54.653: E/log_tag(4324): Error converting result java.lang.NullPointerException
01-29 03:25:54.653: W/dalvikvm(4324): threadid=1: thread exiting with uncaught exception (group=0xb5e98288)
01-29 03:25:54.653: E/AndroidRuntime(4324): FATAL EXCEPTION: main
01-29 03:25:54.653: E/AndroidRuntime(4324): java.lang.NullPointerException
01-29 03:25:54.653: E/AndroidRuntime(4324):     at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at org.json.JSONTokener.nextValue(JSONTokener.java:94)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at org.json.JSONArray.<init>(JSONArray.java:87)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at org.json.JSONArray.<init>(JSONArray.java:103)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at com.nazartt.angtrading.gallery.onActivityCreated(gallery.java:93)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:891)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at android.os.Handler.handleCallback(Handler.java:615)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at android.os.Looper.loop(Looper.java:137)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at android.app.ActivityThread.main(ActivityThread.java:4745)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at java.lang.reflect.Method.invokeNative(Native Method)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at java.lang.reflect.Method.invoke(Method.java:511)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-29 03:25:54.653: E/AndroidRuntime(4324):     at dalvik.system.NativeStart.main(Native Method)
  • 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-17T22:27:19+00:00Added an answer on June 17, 2026 at 10:27 pm

    You have a NetworkOnMainThreadException which occurs on the new versions of Android (3.0+) if you try to do network operations on the main (UI) Thread (StrictMode),. Use an AsyncTask for your network operations, it’s simple to set up, and operates in a logical manner (execute something in background then once you’re done, publish to UI Thread).

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

Sidebar

Related Questions

I'm having with trouble with this script... Everything in it is working except the
I'm really close having a script that fetches JSON from the New York Times
I am using pdb to examine a script having called run -d in an
I am having a jQuery Script to find out the resolution of browser and
I am having a PowerShell script which is walking a directory tree, and sometimes
I am encountering an issue where having a ending script tag inside a quoted
Having problems with a small awk script, Im trying to choose the newest of
Having a problem executing a Python script from a .NET web service. The web
Im having a little trouble with a php script ive made. you can see
I am having problems creating a simple PHP script. The $_GET[give] variable is always

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.