# Please Help (Application Development)



## tcpninja (Jul 23, 2011)

Im trying to develop an application and Im having trouble executing a function when a button is pressed. I have my main.xml for the button setup like this:

and my Activity setup like this:

package com.netbuilder;

import java.io.IOException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class NetBuilderActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public int send() {
return 1;
}

}

My problem is when I press the button the application force closes on me. Obviously I dont want the send function to return 1. I want it to execute a shell command but Im trying to take it one step at a time. I'm completely new to Java.

Any help would be appreciated.


----------



## linuxmotion (Jun 12, 2011)

tcpninja said:


> Im trying to develop an application and Im having trouble executing a function when a button is pressed. I have my main.xml for the button setup like this:
> 
> and my Activity setup like this:
> 
> ...


You still need to define your button In the onCreate() method. I think. 
Ex. 
Button button = this.findviewbyid(R.id.button1);

I can't remember if it should go after or before setContentView() method in the onCreate() method.

Remember you can use 'adb logcat' to view the logs as your running/debugging your app. Its very helpful.

Sent from my Incredible using Tapatalk


----------

