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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:08:19+00:00 2026-06-07T23:08:19+00:00

I am creating an UI using fragments. In onCreate(Bundle savedInstanceState), I am parsing the

  • 0

I am creating an UI using fragments. In onCreate(Bundle savedInstanceState), I am parsing the JSON data. I am getting the the following error:

07-17 15:23:18.089: W/System.err(1368): at
android.os.Looper.loop(Looper.java:132) 07-17 15:23:18.129:
E/AndroidRuntime(1368): FATAL EXCEPTION: main 07-17 15:23:18.129:
E/AndroidRuntime(1368): java.lang.RuntimeException: Unable to start
activity
ComponentInfo{com.afghanread.android/com.afghanread.android.AfghanMagActivity}:
android.view.InflateException: Binary XML file line #8: Error
inflating class fragment 07-17 15:23:18.129: E/AndroidRuntime(1368):
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.app.ActivityThread.access$1500(ActivityThread.java:122) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.os.Handler.dispatchMessage(Handler.java:99) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
android.os.Looper.loop(Looper.java:132) 07-17 15:23:18.129:
E/AndroidRuntime(1368): at
android.app.ActivityThread.main(ActivityThread.java:4025) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
java.lang.reflect.Method.invokeNative(Native Method) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
java.lang.reflect.Method.invoke(Method.java:491) 07-17 15:23:18.129:
E/AndroidRuntime(1368): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
dalvik.system.NativeStart.main(Native Method) 07-17 15:23:18.129:
E/AndroidRuntime(1368): Caused by: android.view.InflateException:
Binary XML file line #8: Error inflating class fragment 07-17
15:23:18.129: E/AndroidRuntime(1368): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:724) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
android.view.LayoutInflater.inflate(LayoutInflater.java:479) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
android.view.LayoutInflater.inflate(LayoutInflater.java:391) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
android.view.LayoutInflater.inflate(LayoutInflater.java:347) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:223)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.app.Activity.setContentView(Activity.java:1780) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
com.afghanread.android.AfghanMagActivity.onCreate(AfghanMagActivity.java:26)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
07-17 15:23:18.129: E/AndroidRuntime(1368): … 11 more 07-17
15:23:18.129: E/AndroidRuntime(1368): Caused by:
java.lang.NullPointerException 07-17 15:23:18.129:
E/AndroidRuntime(1368): at
org.json.JSONTokener.nextCleanInternal(JSONTokener.java:112) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
org.json.JSONTokener.nextValue(JSONTokener.java:90) 07-17
15:23:18.129: E/AndroidRuntime(1368): at
org.json.JSONObject.(JSONObject.java:154) 07-17 15:23:18.129:
E/AndroidRuntime(1368): at
org.json.JSONObject.(JSONObject.java:171) 07-17 15:23:18.129:
E/AndroidRuntime(1368): at
com.afghanread.android.CategoryFragment.parseJSON(CategoryFragment.java:72)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
com.afghanread.android.CategoryFragment.onCreateView(CategoryFragment.java:161)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:713)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:905)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.app.FragmentManagerImpl.addFragment(FragmentManager.java:983)
07-17 15:23:18.129: E/AndroidRuntime(1368): at
android.app.Activity.onCreateView(Activity.java:4141)

My code is :

public class CategoryFragment extends Fragment implements OnItemClickListener {

ArrayList<String> cat = new ArrayList<String>();
ListView list;
DatabaseManager manager;
static String DATABASE_NAME = "afghanread.sqlite";
static Integer DATABASE_VERSION = 1;
TextView text;
TextView cat_name;
int length;
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
        "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux",
        "OS/2" };

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

}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    parseJSON();
    manager = new DatabaseManager(null, DATABASE_NAME, null,
            DATABASE_VERSION);

}

private void parseJSON() {
    try {
        JSONObject jObject = new JSONObject(getJSONData());
        JSONArray jArray = jObject.getJSONArray("data");
        length = jArray.length();
        for (int i = 0; i < length; i++) {
            JSONObject tmpJson = jArray.getJSONObject(i);
            Category category = new Category();

            category.setCategotyId(tmpJson.getInt("category_id"));
            category.setCategoryName(tmpJson.getString("category_name"));

            // manager.insertCategoryDetails(category);

        }
        System.out.println("Jason parsing successful.......");
    } catch (JSONException e) {

        e.printStackTrace();
    }
}

private String getJSONData() {
    HttpPost httpPost = null;
    HttpClient httpClient = null;
    HttpResponse httpResponse = null;
    HttpEntity entity = null;
    InputStream in = null;
    BufferedReader reader = null;
    StringBuilder sb = null;
    String line = null;
    String result = null;
    try {
        httpPost = new HttpPost(
                "http://183.182.84.197:88/Sayyed_fahim/mobile/category.php");
        httpClient = new DefaultHttpClient();
        httpResponse = httpClient.execute(httpPost);
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode == 200) {
            entity = httpResponse.getEntity();
            in = entity.getContent();
            reader = new BufferedReader(new InputStreamReader(in));
            sb = new StringBuilder();
            while ((line = reader.readLine()) != null)
                sb.append(line);

            result = sb.toString();
            result = result.trim();
            result = result.substring(1, result.length());
            Log.i("RESULT", result);
        } else
            Log.e("Error", "" + statusCode);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (in != null) {
                in.close();
                in = null;
            }

            httpPost = null;
            httpClient = null;
            httpResponse = null;
            entity = null;
            in = null;
            reader = null;
            sb = null;
            line = null;

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return result;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    System.out.println("Inside the afghan Read category");
    View view = (View) inflater.inflate(R.layout.categoryfragment, null);
    list = (ListView) view.findViewById(R.id.cat_list);

    /*
     * ArrayAdapter<String> adapter = new
     * ArrayAdapter<String>(getActivity(),
     * android.R.layout.simple_list_item_1, values);
     */
    parseJSON();
    list.setAdapter(new CustomAdapter(getActivity(), R.layout.categoryitem,
            values));

    list.setOnItemClickListener(this);
    return view;
}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    String item = (String) values[arg2];
    LibraryFragment fragment = (LibraryFragment) getFragmentManager()
            .findFragmentById(R.id.library);
    if (fragment != null && fragment.isInLayout()) {
        fragment.setText(item);
    } else {
        Intent intent = new Intent(getActivity().getApplicationContext(),
                LibraryActivity.class);
        intent.putExtra("value", item);
        startActivity(intent);
    }

}

public class CustomAdapter extends BaseAdapter {
    String names[];
    Context mCtx;
    int item;
    LayoutInflater inflater;

    public CustomAdapter(Context ctx, int categoryitem, String[] values) {

        this.names = values;
        this.mCtx = ctx;
        this.item = categoryitem;
        inflater = (LayoutInflater) ctx
                .getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return names.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {

            convertView = inflater.inflate(item, null);
            cat_name = (TextView) convertView.findViewById(R.id.cat_name);

        }

        cat_name.setText(names[position]);

        return convertView;

    }

}

}

How to resolve the issue??

  • 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-07T23:08:20+00:00Added an answer on June 7, 2026 at 11:08 pm

    I would guess that the web call fails and you are passing null to new JSONObject(getJSONData()).
    Is JSONObject jObject = new JSONObject(getJSONData()); line 72 as stated as origin for the nullpointer in your logcat output: com.afghanread.android.CategoryFragment.parseJSON(CategoryFragment.java:72)?

    Not totally related to the error but also a big problem in your code. You are doing a webcall inside the UI-Thread. This will freeze the phone until the json data is loaded from your server. You should at least put all the data loading code inside a AsyncTask and update your UI in the onPostExecute method.

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

Sidebar

Related Questions

I am creating date using following code try { newdatetime = new DateTime(2012, 2,
I am creating package using cmake I am having following structure bin/ bin1 lib/
I am using following plugin http://pinesframework.org/pnotify/ I am creating dialog using following jquery code..
I'm creating a tablet optimised application using fragments. I have a thin navigation fragment
I'm trying to group together radiobuttons that are creating using a for loop and
I am using creating a server/client style program, and it uses tcp connections. Now,
I am creating graphs using GD::Graph::lines . For option set, I have to write
i am dynamically creating radio using jquery as shown belown. but they value only
i am creating div using DOM Element as phototab = document.createElement('div'); phototab.setAttribute('class', 'phototab fleft');
I am creating Schema using Core Service in SDL Tridion 2011 SP1. In the

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.