title: How to pass String containing Special character(&) via intent?
body: <p>I am Implementing an <code>Activity</code> which has a <code>button</code> with the text "Jewellery &amp; Accessories". When I pass the button's text and fire an <code>Intent</code> it results in a <code>NullPointerException</code> in the other <code>Activity</code>? What to do? Any help will be Appreciated. thanks in Advance.</p>
  
  <pre><code>public class Listing extends ListActivity {
  /** Button to provide advance search functionality. */
  
  TextView Paging;
  String tit[];
  String price1[];
  String brand[];
  String value;
  String pst;
  TextView text;
  List&lt;ListRowData&gt; listData;
  String priceAtPosition;
  String typeAtPosition;
  String brandAtPosition;
  ProgressDialog dialog1;
  ProgressDialog dialog;
  AlertDialog alert;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.item_listing_page);
      Intent intent = getIntent();
      savedInstanceState = intent.getExtras();
      value = savedInstanceState.getString("value");
      priceAtPosition = savedInstanceState.getString("priceAtPosition");
      typeAtPosition = savedInstanceState.getString("typeAtPosition");
      brandAtPosition = savedInstanceState.getString("brandAtpositoion");
  
      BottomBarActivity logoBar = (BottomBarActivity) 
                                  findViewById(R.id.bottomBarLayout);
      logoBar.setActivity(this);
  
      TextView txAreaName = (TextView) findViewById(R.id.areaName);
      txAreaName.setText("Shop");
  
      text = (TextView) findViewById(R.id.list_heading);
      text.setText(value);
  
      LoginScreenData loginScreenData = new LoginScreenData();
  
      pst = loginScreenData.getPst();
      Paging = (TextView) findViewById(R.id.textPage);
  
      Button refine = (Button) findViewById(R.id.bt_refine);
      refine.setOnClickListener(btClickListener);
  
      Button sort = (Button) findViewById(R.id.bt_sort);
      sort.setOnClickListener(btClickListener);
  
      Button btnSearch = (Button) findViewById(R.id.bt_search);
      btnSearch.setOnClickListener(btSearchListener);
  
      String Latest1 = "Latest";
  
      listData = new ArrayList&lt;ListRowData&gt;();
  
      methodApiCall(pst, Latest1);
  
  // Get the intent, verify the action and get the query
  
      Intent in = getIntent();
      in.putExtra("value", value);
      if (Intent.ACTION_SEARCH.equals(in.getAction())) {
          String query = in.getStringExtra(SearchManager.QUERY);
          methodApiSearchCall(pst, query);
      }
  
  }
  
  private void methodApiSearchCall(String pst2, String query) {
  
      List&lt;ListRowData&gt; listData;
      listData = new ArrayList&lt;ListRowData&gt;();
  
      String envelope1 = "&lt;req&gt;" + "&lt;term&gt;" + query + "&lt;/term&gt;" + "&lt;/req&gt;";
      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
      request.addProperty("requestXml", envelope1);
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
              SoapEnvelope.VER11);
      envelope.setOutputSoapObject(request);
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
      Object response = null;
      String searchReference[] = null;
      String eventSearchResponse = null;
      String searchImg[] = null;
      String searchTitle[] = null;
  
      try {
          androidHttpTransport.call(SOAP_ACTION1, envelope);
          response = envelope.getResponse();
          eventSearchResponse = response.toString();
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      try {
  
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder db = dbf.newDocumentBuilder();
          Document doc = db.parse(new InputSource(new StringReader(
                  eventSearchResponse)));
  
          // normalize the document
          doc.getDocumentElement().normalize();
  
          NodeList nodelistDet = doc.getElementsByTagName("det");
  
          for (int j = 0; j &lt; nodelistDet.getLength(); j++) {
  
              Node node1 = nodelistDet.item(0);
              Element fstelement1 = (Element) node1;
              NodeList lnlist = fstelement1.getElementsByTagName("ln");
              searchReference = new String[lnlist.getLength()];
              searchImg = new String[lnlist.getLength()];
              searchTitle = new String[lnlist.getLength()];
  
              for (int i = 0; i &lt; lnlist.getLength(); i++) {
  
                  Element lnelement2 = (Element) lnlist.item(i);
                  searchReference[i] = lnelement2.getAttribute("ref");
                  searchImg[i] = lnelement2.getAttribute("img");
                  searchTitle[i] = lnelement2.getAttribute("tit");
              }
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      for (int i = 0; i &lt; searchTitle.length; i++) {
  
          ListRowData rowData = new ListRowData();
          rowData.setSearchReference(searchReference[i]);
          rowData.setSearchImg(searchImg[i]);
          rowData.setSearchTitle(searchTitle[i]);
          listData.add(rowData);
      }
      method(listData);
  
  }
  
  public void methodApiCall(String pstcode, String latest) {
  
      List&lt;ListRowData&gt; listData = new ArrayList&lt;ListRowData&gt;();
      String envelope1 = "&lt;req&gt;" + "&lt;pst&gt;" + pstcode + "&lt;/pst&gt;" + "&lt;sort&gt;"
              + latest + "&lt;/sort&gt;" + "&lt;dept&gt;WOMEN&lt;/dept&gt;" + "&lt;cat&gt;" + value
              + "&lt;/cat&gt;" + "&lt;prmax&gt;" + priceAtPosition + "&lt;/prmax&gt;"
              + "&lt;brand&gt;" + brandAtPosition + "&lt;/brand&gt;" + "&lt;pp&gt;10&lt;/pp&gt;"
              + "&lt;inx&gt;1&lt;/inx&gt;" + "&lt;/req&gt;";
  
      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
      request.addProperty("requestXml", envelope1);
  
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
              SoapEnvelope.VER11);
      envelope.setOutputSoapObject(request);
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  
      Object response = null;
      String[] description = null;
      String salePrice[] = null;
      String reference[] = null;
      String image[] = null;
      String shopSearchResponse = null;
  
      try {
          androidHttpTransport.call(SOAP_ACTION, envelope);
          response = envelope.getResponse();
          shopSearchResponse = response.toString();
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      try {
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder db = dbf.newDocumentBuilder();
          Document doc = db.parse(new InputSource(new StringReader(
                  shopSearchResponse)));
          // normalize the document
          doc.getDocumentElement().normalize();
          NodeList rootnode = doc.getElementsByTagName("resp");
          Node node = rootnode.item(0);
          Element fstelement = (Element) node;
          NodeList reglist = fstelement.getElementsByTagName("cnt").item(0)
                  .getChildNodes();
          Node nvalue = (Node) reglist.item(0);
          NodeList reglist1 = fstelement.getElementsByTagName("pp").item(0)
                  .getChildNodes();
          Node nvalue1 = (Node) reglist1.item(0);
          NodeList reglist2 = fstelement.getElementsByTagName("inx").item(0)
                  .getChildNodes();
          Node nvalue2 = (Node) reglist2.item(0);
          String count = nvalue.getNodeValue();
          String index = nvalue2.getNodeValue();
          String perPage = nvalue1.getNodeValue();
          Paging.setText(index + " - " + perPage + " out of " + count);
          NodeList nodelist = doc.getElementsByTagName("det");
  
          for (int j = 0; j &lt; nodelist.getLength(); j++) {
  
              Node node1 = nodelist.item(0);
              Element fstelement1 = (Element) node1;
              NodeList lnlist = fstelement1.getElementsByTagName("ln");
              description = new String[lnlist.getLength()];
              tit = new String[lnlist.getLength()];
              salePrice = new String[lnlist.getLength()];
              reference = new String[lnlist.getLength()];
              price1 = new String[lnlist.getLength()];
              brand = new String[lnlist.getLength()];
              image = new String[lnlist.getLength()];
  
              for (int i = 0; i &lt; lnlist.getLength(); i++) {
  
                  Element lnelement = (Element) lnlist.item(i);
                  description[i] = lnelement.getAttribute("desc");
                  tit[i] = lnelement.getAttribute("tit");
                  salePrice[i] = lnelement.getAttribute("sale");
                  reference[i] = lnelement.getAttribute("ref");
                  price1[i] = lnelement.getAttribute("price");
                  brand[i] = lnelement.getAttribute("brand");
                  image[i] = lnelement.getAttribute("img");
              }
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      for (int i = 0; i &lt; tit.length; i++) {
  
          ListRowData rowData = new ListRowData();
          rowData.setDescription(description[i]);
          rowData.setNew_Price(salePrice[i]);
          rowData.setOld_Price(price1[i]);
          rowData.setTitle(tit[i]);
          rowData.setImage(image[i]);
          listData.add(rowData);
      }
  
      TextView totalitem = (TextView) findViewById(R.id.tx_totalItem);
      totalitem.setText(Integer.toString(tit.length) + " Items");
      ListView lv = getListView(); // Getting list view to activity
      setListAdapter(new ListCustomAdapter(this,
              R.layout.shop_list_items_row, listData));
  
      // sets onItemClick event on list item
      lv.setOnItemClickListener(itemClickListener);
  
  }
  
  private OnClickListener btSearchListener = new OnClickListener() {
  
      public void onClick(View view) {
          Intent in = new Intent();
          in.putExtra("value", value);
          onSearchRequested();
      }
  };
  
  /** OnClickListener instance to perform onClick on buttons. */
  
  private OnClickListener btClickListener = new OnClickListener() {
  
      public void onClick(View v) {
          Intent myIntent;
          if (v.getId() == R.id.bt_refine) {
              myIntent = new Intent().setClass(getApplicationContext(),
                      RefinePageActivity.class);
              myIntent.putExtra("title", tit);
              myIntent.putExtra("price", price1);
              myIntent.putExtra("brand", brand);
              myIntent.putExtra("value1", value);
              startActivity(myIntent);
          }
  
          else if (v.getId() == R.id.bt_sort) {
  
              final String items[] = { "Latest", "Title", "Price" };
              AlertDialog.Builder builder = new AlertDialog.Builder(
                      Listing.this);
              builder.setTitle("Pick a Item for sort");
              builder.setSingleChoiceItems(items, -1,
                      new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int item) {
                              listData = new ArrayList&lt;ListRowData&gt;();
                              methodApiCall("Default", items[item]);
                              alert.dismiss();
                              dialog1 = ProgressDialog.show(Listing.this,
                                      "loading please wait",
                                      "Loading. Please wait...", true);
                              new Thread() {
                                  public void run() {
                                      try {
                                          // performBackgroundProcess1();
                                          sleep(3000, 000);
                                      } catch (Exception e) {
                                          Log.e("tag", e.getMessage());
                                      }
                                      // dismiss the progress dialog
                                      dialog1.dismiss();
  
                                  }
                              }.start();
                          }
                      });
              alert = builder.create();
              alert.show();
          }
      }
  };
  
  void method(List&lt;ListRowData&gt; ll) {
  
      setListAdapter(new ListCustomAdapterShopSearch(this,
              R.layout.events_search_list_item_row, ll));
      ListView lv1 = getListView();
      lv1.setOnItemClickListener(itemClickListener);
  }
  
  /** OnItemClickListener instance to perform itemClick event on items. */
  private OnItemClickListener itemClickListener = new OnItemClickListener() {
      public void onItemClick(AdapterView&lt;?&gt; parent, View view,
              final int position, long id) {
  
          dialog = ProgressDialog.show(view.getContext(),
                  "loading please wait", "Loading. Please wait...", true);
          new Thread() {
              public void run() {
                  try {
                      Intent inDetail = new Intent().setClass(
                              getApplicationContext(), DetailPage.class);
                      inDetail.putExtra("Position", position);
                      startActivity(inDetail);
                  } catch (Exception e) {
                      Log.e("tag", e.getMessage());
                  }
                  // dismiss the progress dialog
                  dialog.dismiss();
              }
          }.start();
      }
  };
  }
  </code></pre>
  
  <p>Log output:</p>
  
  <pre><code>05-24 12:02:49.232: E/AndroidRuntime(849): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.capstrov/commerce.app.lib.shop.Listing}: java.lang.NullPointerException
  05-24 12:02:49.232: E/AndroidRuntime(849):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at android.os.Handler.dispatchMessage(Handler.java:99)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at android.os.Looper.loop(Looper.java:123)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at android.app.ActivityThread.main(ActivityThread.java:4627)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at java.lang.reflect.Method.invokeNative(Native Method)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at java.lang.reflect.Method.invoke(Method.java:521)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at dalvik.system.NativeStart.main(Native Method)
  05-24 12:02:49.232: E/AndroidRuntime(849): Caused by: java.lang.NullPointerException
  05-24 12:02:49.232: E/AndroidRuntime(849):  at commerce.app.lib.shop.Listing.methodApiCall(Listing.java:280)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at commerce.app.lib.shop.Listing.onCreate(Listing.java:110)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  05-24 12:02:49.232: E/AndroidRuntime(849):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  05-24 12:02:49.232: E/AndroidRuntime(849):  ... 11 more
  </code></pre>