execute httppost error

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

execute httppost error

Postby Highor » Sun Dec 18, 2011 5:18 pm

Hello all,

First of all i don't know if i am in the right forum for this, sorry if not.

I am trying to build my first project, i followed some tutorials but i can't get it working.
What i am trying to do is; when i click on a button i simply make a httppost to an url, without any post values. (Not sure if this is possible though).

If i run the script i just get "error" in the title, and no message.

This is what i got:

public class AppActivity extends Activity {
private Button button1;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
saveMessage();
}
});
}

public void saveMessage() {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.2.2/communication/index.php");
httpclient.execute(httppost);
okMessage();
}
catch(Exception e){
errorMessage(e.getMessage());
}
}

public void okMessage() {
new AlertDialog.Builder(this)
.setMessage(R.string.test)
.setTitle(R.string.test)
.setCancelable(true)
.show();
}

public void errorMessage(String message) {
new AlertDialog.Builder(this)
.setMessage(message)
.setTitle(R.string.error)
.setCancelable(true)
.show();
}
}

Thanks for your help.
Highor
Freshman
Freshman
 
Posts: 2
Joined: Sun Dec 18, 2011 5:07 pm

Top

Re: execute httppost error

Postby Highor » Sun Dec 18, 2011 8:58 pm

The problem lies in this lines:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.2.2/communication/index.php");
httpclient.execute(httppost);
Highor
Freshman
Freshman
 
Posts: 2
Joined: Sun Dec 18, 2011 5:07 pm

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: Exabot [Bot] and 8 guests