title: Error in Layout Inflater in fragment
body: <p>I am creating an UI using fragments. In onCreate(Bundle savedInstanceState), I am parsing the JSON data. I am getting the the following error:</p>
  
  <blockquote>
    <p>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)</p>
  </blockquote>
  
  <p>My code is :</p>
  
  <pre><code>public class CategoryFragment extends Fragment implements OnItemClickListener {
  
  ArrayList&lt;String&gt; cat = new ArrayList&lt;String&gt;();
  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 &lt; 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&lt;String&gt; adapter = new
       * ArrayAdapter&lt;String&gt;(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&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
      String item = (String) values[arg2];
      LibraryFragment fragment = (LibraryFragment) getFragmentManager()
              .findFragmentById(R.id.library);
      if (fragment != null &amp;&amp; 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;
  
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>How to resolve the issue??</p>