2013-02-23 97 views
0

基本上我在數據庫端設置了一些成員,我也做了一個註冊表單,它將數據發佈到數據庫,但是我遇到的問題是我的程序不會啓動活動。當我註釋掉它的工作部分的httppost部分時,所以我相信我的問題與PHP文件有關,但是已經發布了我已經完成的Java代碼。在另一個問題中,我將發佈PHP代碼。android httppost錯誤

try 
{ 
    httpclient = new default HttpClient(); 
    httppost = new HttpPost(""); 
    nameValuePair = new arrayList <NameValuePair> (1); 
    nameValuePair . add(new BasicNameValuePair("email", email . getText() . toString() . trim())); 
    nameValuePair . add(new BasicNameValuePair("password", password . getText() . toString() . trim())); 
    httppost . setEntity(new UrlEncodedF or mEntity(nameValuePair)); 
    response = httpclient . execute(httppost); 
    ResponseHandler <String> responseHandler = new BasicResponseHandler(); 
    final Stringresponse = httpclient . execute(httppost, responseHandler); 
    loginErrorMsg . setText("" + response); 

    if(response . equalsIgnorecase ("Log in Successful")) 
    { 
     startActivity(new Intent(LoginActivity . this, HomescreenActivity . class)); 
    } 
} 
catch(Exceptione) 
{ 
    e.printStackTrace(); 
} 
+1

顯示完整的堆棧跟蹤 – moDev 2013-02-23 19:55:15

+0

確定。謝謝你的回覆 – Moe 2013-02-27 15:22:03

+0

02-27 15:35:31.791:W/KeyCharacterMap(118):沒有鍵盤的ID 0 02-27 15:35:31.791:W/KeyCharacterMap(118):使用默認鍵盤映射: system/usr/keychars/qwerty.kcm.bin 02-27 15:36:02.321:W/SingleClientConnManager(342):無效使用SingleClientConnManager:仍然分配連接。 02-27 15:36:02.321:W/SingleClientConnManager(342):確保在分配另一個連接之前釋放連接。 – Moe 2013-02-27 15:39:04

回答

0

很難知道問題沒有查看堆棧跟蹤,但我會說問題是在UI(主)線程上發出網絡請求。

您需要在單獨的線程上執行所有網絡任務。

請參閱此link的教程。

+0

嗯感謝您的回覆,我會給這個鏡頭並回復你。謝謝 – Moe 2013-02-27 15:12:46

0

您是否請求了Internet權限?

<uses-permission android:name="android.permission.INTERNET" /> 
+0

是的,我已經完成了。它以我的註冊表格將數據發佈到數據庫的方式連接到數據庫。它只是不啓動活動。我認爲它與我的PHP文件。 http://stackoverflow.com/questions/15046825/android-and-php-login-error 謝謝 – Moe 2013-02-27 15:16:31

0
nameValuePair = new ArrayList<NameValuePair>(1); 

    nameValuePair.add(new BasicNameValuePair("email", email.getText().toString().trim())); 
    nameValuePair.add(new BasicNameValuePair("password", password.getText().toString().trim())); 
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePair)); 

    response = httpclient.execute(httppost); 

    ResponseHandler<String> responseHandler = new BasicResponseHandler(); 
    final HttpResponse responsed = httpclient.execute(httppost, responseHandler); 

    final String response= EntityUtils.toString(responsed .getEntity()); 

    loginErrorMsg.setText(""+response); 

    if(response.equalsIgnoreCase("Log in Successful")) 
      startActivity(new Intent(LoginActivity.this, HomescreenActivity.class));                  
} 
catch(Exception e){ 
     e.printStackTrace(); 
}