2013-02-23 289 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(); 
}