0

I am testing with HttpGet to simply see if it would download anything from my website, but the application crashes on startup. Anyone know why?

package com.httptest;

import java.net.URI;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import org.apache.http.client.methods.HttpRequestBase;


public class httptest extends Activity {
    /** Called when the activity is first created. */
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button  recieve = (Button)findViewById(R.id.Button);
        recieve.setOnClickListener((OnClickListener) this);
    }
    
    @SuppressWarnings("null")
	public void onClick(View v) {
        String url = "http://fuggles7.110mb.com/";
        HttpRequestBase http = null;
        http.setURI(URI.create(url));
    }
}
2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by fuggles
0

I did some more Googling on it. And this is my newest code. It still crashes.

package com.httptest;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;



public class httptest extends Activity {
    /** Called when the activity is first created. */
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        Button load = (Button)findViewById(R.id.Button);
        load.setOnClickListener((OnClickListener) this);
    }
	
	public void onClick(View v) {
        TextView text = (TextView)findViewById(R.id.Text);
		getData(text);
	}
    

	public void getData(TextView content) {
		String url = "http://fuggles7.110mb.com";
		HttpClient client = new DefaultHttpClient();
		HttpGet request = new HttpGet(url);
		
		try {
			@SuppressWarnings("unused")
			HttpResponse response = client.execute(request);
			content.setText("Loaded content!");
		}
		catch(Exception ex) {
			content.setText("Failed to load content!");
		}
	}
}
0

To make sure that it wasn't the type of the HttpResponse variable being put into the TextView crashing it.

0

Well that message can let you know something is wrong, however summary from stack trace will indicate what is reason...

0

Well it crashes on startup. The button or anything doesn't even get drawn when it crashes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.