Note that there are some explanatory texts on larger screens.

plurals
  1. POgetByName in POST HTTP request
    text
    copied!<p>I'm trying to get the ip address of a host name then use it in the POST Http request URL i'm sending to everything was working find and after adding the getByName line it suddenly crashed So please help me and tell me exactly what could be the problem ? Thank you in advance</p> <p>Logindb.java</p> <pre><code> package com.example.loginad; import java.net.InetAddress; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class Logindb extends Activity { Button login; EditText u,p; TextView res; String result; String x="mobile"; String host=""; Thread mBack; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.logindb); login=(Button)findViewById(R.id.login); u=(EditText)findViewById(R.id.u); p=(EditText)findViewById(R.id.p); res=(TextView)findViewById(R.id.res); mBack = new Thread(new Runnable() { public void run() { try { InetAddress address=null; address = InetAddress.getByName("Osama-PC"); host=address.getHostAddress(); } catch(Exception e) { e.printStackTrace(); } } }); login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new MyAsyncTask().execute(u.getText().toString(),p.getText().toString()); } }); } private class MyAsyncTask extends AsyncTask&lt;String, Integer, Boolean&gt;{ @Override protected Boolean doInBackground(String... params) { // TODO Auto-generated method stub boolean success = postData(params[0],params[1]); return success; } protected void onPostExecute(Boolean localres){ if (localres){ res.setText("A Correct Username and Password"); }else{ res.setText("Incorrect Username or Password"); } Toast.makeText(getApplicationContext(), "command sent", Toast.LENGTH_LONG).show(); } protected void onProgressUpdate(Integer... progress){ //pb.setProgress(progress[0]); //Toast.makeText(getApplicationContext(), "Done", Toast.LENGTH_LONG).show(); } public Boolean postData(String a,String b) { ArrayList&lt;NameValuePair&gt; postParameters = new ArrayList&lt;NameValuePair&gt;(); postParameters.add(new BasicNameValuePair("username", a)); postParameters.add(new BasicNameValuePair("password", b)); postParameters.add(new BasicNameValuePair("mobileid",x)); // String valid = "1"; String response = null; try { // Toast.makeText(getApplicationContext(), host.toString(), Toast.LENGTH_LONG).show(); response = CustomHttpClient.executeHttpPost("http://"+host+"/new/check.php",postParameters); //now in result you will have the response from php file either 0 or 1. result = response.toString(); // res = res.trim(); result = result.replaceAll("\\s+", ""); // error.setText(res); } catch (Exception e) { //res.setText(e.toString()); } return "1".equals(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.logindb, menu); return true; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload