我的網絡服務出現問題。我的佈局包含這些領域按鈕值的空指針異常
username edittextbox
password edittextbox
gender button(male), button(female)
mailid edittextbox
每當我點擊按鈕的男性對性別的選擇應採取的字符串值作爲男性,女性應該採取女性。我無法寫出確切的代碼,因爲我是新來的android becoz,我得到了logcat中的空指針異常。
我想添加這些字符串值來請求我的web服務的obj將數據發送到服務器,如request.addProperty(「gender」,gender);根據用戶選擇
有人請幫我寫的性別選擇確切的代碼,這樣我就不會在logcat中得到任何NPE
代碼
Button regmalebtn;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
public void register() {
Log.v(TAG, "Trying to Login");
EditText etxt_user = (EditText) findViewById(R.id.regetfirstname);
EditText etxt_pass = (EditText) findViewById(R.id.regetlastname);
EditText etxt_dob = (EditText) findViewById(R.id.regetdob);
EditText etxt_email = (EditText) findViewById(R.id.regetemail);
EditText etxt_password = (EditText) findViewById(R.id.regetpwd);
EditText etxt_mobno = (EditText) findViewById(R.id.regetmobno);
EditText deviceid = null;
String fname = etxt_user.getText().toString();
String lname = etxt_pass.getText().toString();
String dob = etxt_dob.getText().toString();
String email = etxt_email.getText().toString();
String password = etxt_password.getText().toString();
String mobno = etxt_mobno.getText().toString();
String gender= regmalebtn.getText().toString();
int latitude =**;
int longitude= **;
String device_id= "12345";
// regmalebtn.sette
// DefaultHttpClient client = new DefaultHttpClient();
//HttpPost httppost = new HttpPost(
// "http://.....");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
//String response1 = request.getProperty(0).toString() ;
request.addProperty("fname", fname);
request.addProperty("lname", lname);
request.addProperty("dateofbirth", dob);
request.addProperty("email", email);
request.addProperty("password", password);
request.addProperty("mobno", mobno);
request.addProperty("latitude", latitude);
request.addProperty("longitude", longitude);
request.addProperty("device_id", device_id);
request.addProperty("gender", gender);
//request.addProperty("latitude',latitude);
try {
androidHttpTransport.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive resultsRequestSOAP = (SoapPrimitive) soapEnvelope
.getResponse();
//SoapObject result = (SoapObject) soapEnvelope.getResponse();
String resultData;
resultData = request.getProperty(0).toString();
} catch (Exception e) {
e.printStackTrace();
}
}
這些都是logcat的錯誤
06-16 11:55:58.955: ERROR/AndroidRuntime(471): FATAL EXCEPTION: Thread-8
06-16 11:55:58.955: ERROR/AndroidRuntime(471): java.lang.NullPointerException
06-16 11:55:58.955: ERROR/AndroidRuntime(471): at com.soap.Register.register(Register.java:125)
06-16 11:55:58.955: ERROR/AndroidRuntime(471): at com.soap.Register$1$1.run(Register.java:66)
06-16 11:55:58.965: WARN/ActivityManager(58): Force finishing activity com.soap/.Register
它看起來就像你在'com.soap.Register'類中的內部'Runnable'類中有NPE一樣。 – inazaruk 2011-06-16 06:53:39
發佈您的代碼,其中來自TextView的 – ngesh 2011-06-16 06:54:26
您的初始化按鈕,獲取串@inazaruk喜,其實即時通訊呼叫按鈕內部的寄存器方法點擊這樣signin.setOnClickListener(新OnClickListener(){ \t \t \t公共無效的onClick(視圖v) { \t \t \t \t的ShowDialog(0); \t \t 噸=新主題(){ \t \t \t \t \t公共無效的run(){ \t \t \t \t \t \t register(); \t \t \t \t \t} \t \t \t \t}; \t \t \t \t t。開始(); \t \t \t} \t \t}); \t} – Randroid 2011-06-16 06:55:44