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));
    }
}

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!");
		}
	}
}

Why you are printing some silly text message instead of getting stack trace of what ever exception throw?

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

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

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

It could be somewhere else. Would you like to take a look at the other parts of my project?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.