0

基本上我已经在数据库端设置了一些成员,我还做了一个注册表单,它将数据发布到数据库,但我遇到的问题是我的程序不会启动活动。当我注释掉它的 httppost 部分时,它可以工作,所以我相信我的问题与 PHP 文件有关,但已经发布了我所做的 java 代码。在另一个问题中,我将发布 PHP 代码。

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();
}
4

3 回答 3

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();
}
于 2013-02-23T19:55:54.653 回答
0

您是否请求了 Internet 权限?

    <uses-permission android:name="android.permission.INTERNET" />
于 2013-02-23T19:52:08.873 回答
0

如果不查看堆栈跟踪,很难知道问题所在,但我想说问题在于在 UI(主)线程上发出网络请求。

您需要在单独的线程上执行所有网络任务。

请参阅此链接以获取教程。

于 2013-02-23T19:50:05.683 回答