[Android Q&A, Help & Troubleshooting] hasham19:
Hi i am new to android developing. I don't know is this the right section to post but i really need help on this. My app is a remote control and and it has to send strings to the server (PC) by clicking the buttons. Somehow my app crashes when i click the button :confused: . I cant figure out the problem. Can anyone help me please?? :(:( .

here I'm pasting the code:

public class MyAppActivity extends Activity {
/** Called when the activity is first created. */
Button mButton;
EditText mEdit;
TextView mTextView;
String ip;
Socket s;

InputStream is;
InputStreamReader isr;
BufferedReader br;
DataOutputStream os;
//PrintWriter pw;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.addip);

mButton = (Button) findViewById(R.id.button1);
mEdit = (EditText) findViewById(R.id.editText1);
mTextView = (TextView) findViewById(R.id.tConnectStatus);

mButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String ip = mEdit.getText().toString();

try {
s = new Socket(ip, 2222);

is = s.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
os = new DataOutputStream(s.getOutputStream());
//pw = new PrintWriter(os, true);
// s.close();
} catch (Exception ex) {
// System.out.println(ex);
CharSequence statusMesg = "Please Enter the Correct IP ";
mTextView.setText(statusMesg);

}

// Wificlient conState = new Wificlient();

if (s.isConnected()) {
CharSequence statusMesg = "Connected";
mTextView.setText(statusMesg);
Intent startAcontroller = new Intent(
"my.hasham.joy.app.ACONTROLLER");
startActivity(startAcontroller);

} else {
CharSequence statusMesg = "Please Enter the Correct IP ";
mTextView.setText(statusMesg);
// finish();
}
// Intent startAcontroller = new
// Intent("my.hasham.joy.app.ACONTROLLER");
// startActivity(startAcontroller);

}

});

}

public void sendForward(String cmd) throws IOException {

os.writeUTF(cmd);

}

public void sendBackward(String cmd) throws IOException {

os.writeUTF(cmd);

}

public void sendLeft(String cmd) throws IOException {

os.writeUTF(cmd);

}

public void sendRight(String cmd) throws IOException {

os.writeUTF(cmd);

}

public void sendStart(String cmd) throws IOException {

os.writeUTF(cmd);

}

public void sendSelect(String cmd) throws IOException {

os.writeUTF(cmd);

}

public void sendB(String cmd) throws IOException {

os.writeUTF(cmd);

}

public void sendA(String cmd) throws IOException {

os.writeUTF(cmd);

}

}

and the other activity:

public class Acontroller extends Activity {

Button bForward;
Button bBackward;
Button bRight;
Button bLeft;
Button bSelect;
Button bStart;
Button bB;
Button bA;
public MyAppActivity command = new MyAppActivity();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.nesskin);

bForward = (Button) findViewById(R.id.bForward);
bBackward = (Button) findViewById(R.id.bBackward);
bRight = (Button) findViewById(R.id.bRight);
bLeft = (Button) findViewById(R.id.bLeft);
bSelect = (Button) findViewById(R.id.bSelect);
bStart = (Button) findViewById(R.id.bStart);
bA = (Button) findViewById(R.id.bA);
bB = (Button) findViewById(R.id.bB);

bForward.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

try {
command.sendForward("forward");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});

bBackward.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//	MyAppActivity command = new MyAppActivity();
try {
command.sendBackward("backward");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});
bLeft.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//	MyAppActivity command = new MyAppActivity();
try {
command.sendLeft("Left");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});
bRight.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//	MyAppActivity command = new MyAppActivity();
try {
command.sendRight("right");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});
bSelect.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//	MyAppActivity command = new MyAppActivity();
try {
command.sendSelect("select");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});
bStart.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//	MyAppActivity command = new MyAppActivity();
try {
command.sendStart("start");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});
bA.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//	MyAppActivity command = new MyAppActivity();
try {
command.sendA("a");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});
bB.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//	MyAppActivity command = new MyAppActivity();
try {
command.sendB("b");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});

}

}

Please if anyone can help me :(:( . I really need to get this done.