Results 1 to 6 of 6
  1. #1

    how to debug runtime exception in AsyncTask?

    I am a relatively new to Android development, so pls, bear with me.

    I took a post from mobiledevtuts android/android-http-with-asynctask-example/
    xml and php info is also there.
    I/ve added 2 line to the xml:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_ST ATE"/>

    The app dies after httpclient.execute()
    Any ideas?

    Below is my code from the

    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.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ProgressBar;
    import android.widget.Toast;

    public class MainActivity extends ActionBarActivity implements OnClickListener {
    private EditText value;
    private int lhError;
    private Button btn;
    private ProgressBar pb;
    protected void onCreate(Bundle savedInstanceState) {
    lhError = 0;
    lhError = 0;

    public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);
    return true;

    public void onClick(View v) {
    // TODO Auto-generated method stub
    // out of range
    Toast.makeText(this, "please enter something", Toast.LENGTH_LONG).show();
    new MyAsyncTask().execute(value.getText().toString());


    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();
    if (id == {
    return true;
    return super.onOptionsItemSelected(item);
    private class MyAsyncTask extends AsyncTask<String, Integer, Double>{

    protected Double doInBackground(String... params) {
    // TODO Auto-generated method stub
    return null;

    protected void onPostExecute(Double result){
    Toast.makeText(getApplicationContext(), "command sent", Toast.LENGTH_LONG).show();
    protected void onProgressUpdate(Integer... progress){

    public void postData(String valueIWantToSend) {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();

    HttpPost httppost = new HttpPost("");

    try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("myHttpData", valueIWantToSend));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);
    lhError = 1;

    } catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    lhError = -2;
    } catch (IOException e) {
    // TODO Auto-generated catch block
    lhError = -3;



  2. #2
    please attach the log ,

  3. #3
    You want to send a value pair over http(s) and because you are using async task your debugger doesn't look inside the task?
    Could you give a little more info on what you want to do? Do you own/lease the server on the receiving side? Does the server give a standard answer to what you intend to do and if so do you need to capture the answer? Is the protocol only http or could it also be https? Does the server accept JSONObjects? Have you tried Log.d("TAG", variables) for logging inside the asynctask? Do you need feedback (progressbar) for a keypair value? And if not: Have you considered using the ExecutorService with a fixed threadpool and a callable with an arrayresult as you try to do with List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();??

    Please shed some light for us - eager to help you )))

  4. #4
    I just realized that this post is from may 2014. Gulp!

  5. #5
    Join Date
    Feb 2015

    HTC Desire 820, Samsung Galaxy Note 3 Neo, Nexus 6, Micromax Canvas Knight
    Resume it with the Eclipse debugger.
    Read out the same problem mentioned here, may it will help.

  6. #6
    Thank you, nz and m3r for your help. I think the "resume" probably would have worked at the time. But I gave up on that example, found another one,
    and made that work.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts