title: Android sign up user on database
body: <p>I have been given a registration api to use signup a user onto the backend
  But it does not seem to work.Need help.Thanks.</p>
  
  <p>Following is the registration api followed by the code</p>
  
  <p>Params : username, email, pwd(password), cname(company name), cmobile(company mobile number), cwebsite(company website), cfbaddress( company’s fb address), cbssid(company’s bssid)
  <a href="http://52.74.103.52/pages/create_user_using_app.json?username=mega&amp;email=megavasu08%20@gmail.com&amp;pwd=password&amp;cname=ttd&amp;cmobile=7896325410&amp;cwebsite=website_address&amp;cfb%20address=http://facebook.com&amp;cbssid=48f8b3aa05c5" rel="nofollow">Link</a></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  EditText inUsername,inEmail,inPassword,inCompanyName,inCompanyWeb,inCompanyPh,inCompanyFb,inBSSid;
  TextView txt;
  Button btnSignup;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      inUsername=(EditText)findViewById(R.id.input_user);
      inEmail=(EditText)findViewById(R.id.input_email_user);
      inCompanyPh=(EditText)findViewById(R.id.input_company_phone_number);
      inPassword=(EditText)findViewById(R.id.input_password_user);
      inCompanyName=(EditText)findViewById(R.id.input_company_name);
      inCompanyFb=(EditText)findViewById(R.id.input_company_fb_address);
      inBSSid=(EditText)findViewById(R.id.input_company_bssid);
      inCompanyWeb=(EditText)findViewById(R.id.input_company_website);
      txt=(TextView)findViewById(R.id.txt_response);
      btnSignup=(Button)findViewById(R.id.btn_signup_user);
  
      inUsername.setText("mega");
      inEmail.setText("megasu08@gmail.com");
  
      inPassword.setText("password");
      inCompanyName.setText("ttd");
  
      inCompanyWeb.setText("&lt;website address as given&gt;");
      inCompanyPh.setText("7896325410");
  
      inCompanyFb.setText("&lt;fb address as given&gt;");
      inBSSid.setText("48f8b3aa05c5");
  
  
      btnSignup.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              InputStream inputStream = null;
              String result = "";
  
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost("http://52.74.103.52/pages/create_user_using_app");
  
  
              try {
                  // Add your data
                  List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
  
                  nameValuePairs.add(new BasicNameValuePair("username", inUsername.getText().toString()));
                  nameValuePairs.add(new BasicNameValuePair("email", inEmail.getText().toString()));
  
                  nameValuePairs.add(new BasicNameValuePair("pwd", inPassword.getText().toString()));
                  nameValuePairs.add(new BasicNameValuePair("cname", inCompanyName.getText().toString()));
  
                  nameValuePairs.add(new BasicNameValuePair("cwebsite", inCompanyWeb.getText().toString()));
                  nameValuePairs.add(new BasicNameValuePair("cmobile", inCompanyPh.getText().toString()));
  
                  nameValuePairs.add(new BasicNameValuePair("cfbaddress", inCompanyFb.getText().toString()));
                  nameValuePairs.add(new BasicNameValuePair("cbssid", inBSSid.getText().toString()));
  
                  httppost.setHeader("Accept", "application/json");
                  httppost.setHeader("Content-type", "application/json");
                  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                  Log.d("ERROR", httppost.getEntity().toString());
                  // Execute HTTP Post Request
                  HttpResponse response = httpclient.execute(httppost);
  
                  inputStream = response.getEntity().getContent();
  
                  // 10. convert inputstream to string
                  if (inputStream != null)
                      result = convertInputStreamToString(inputStream);
                  else
                      result = "Did not work!";
  
                  Log.d("ERROR",inputStream.toString());
                  Log.d("ERROR",result.toString());
  
                  txt.setText(result);
  
              } catch (ClientProtocolException e) {
                  // TODO Auto-generated catch block
              } catch (IOException e) {
                  // TODO Auto-generated catch block
              }
  
          }
      });
  
  
  
  }
  private String convertInputStreamToString(InputStream inputStream) throws IOException{
      BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
      String line = "";
      String result = "";
      while((line = bufferedReader.readLine()) != null)
          result += line;
  
      inputStream.close();
      return result;
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>LogCat :</p>
  
  <pre><code>android.os.NetworkOnMainThreadException
          at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
          at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:110)
          at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
          at libcore.io.IoBridge.connect(IoBridge.java:122)
          at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
          at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
          at java.net.Socket.connect(Socket.java:882)
          at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:124)
          at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:149)
          at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
          at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
          at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:365)
          at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
          at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
          at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470)
          at com.example.anupamchugh.restraunt.MainActivity$1.onClick(MainActivity.java:100)
          at android.view.View.performClick(View.java:4780)
          at android.view.View$PerformClick.run(View.java:19866)
          at android.os.Handler.handleCallback(Handler.java:739)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5254)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  </code></pre>