I am just trying to initiliazing by variables by Buttons and variables.
But when i try to initialize the if I set my OnClickListeners for the buttons the applications gets stopped unexpectedly.
If i comment the lines of setting the OnClickListener the application is working fine. So I am sure that the problem is definitely with the OnClickListener.I have also attached my activity in the AndroidManifest.XML
The class name is Data.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Data extends Activity implements OnClickListener {
Button start, startFor;
EditText sendET;
TextView gotAnswer;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
initialise();
start.setOnClickListener(this);
**startFor.setOnClickListener(this);
setContentView(R.layout.get);**
}
private void initialise() {
// TODO Auto-generated method stub
start = (Button) findViewById(R.id.bSA);
startFor = (Button) findViewById(R.id.bSAFR);
sen
dET = (EditText) findViewById(R.id.etSend);
gotAnswer = (TextView) findViewById(R.id.tvGot);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case (R.id.bSA):
break;
case (R.id.bSAFR):
break;
}
}
}
and the corresponding Manifest added activity is
<activity
android:name=".Data"
android:label="@string/app_name" >
</activity>
Whats the error in setting the OnClickListener… is their something wrong that I am doing ?
You haven’t specified a view for your activity. Just after you call
super.onCreate(..), callsetContentView(R.id.mylayoutid), where mylayoutid is the name of the xml layout which contains the buttons.