Php android httppost错误

Php android httppost错误,php,android,mysql,Php,Android,Mysql,基本上,我已经在数据库端设置了一些成员,我还做了一个注册表,它将数据发布到数据库中,但我遇到的问题是,我的程序不会启动活动。当我注释掉httppost部分时,它是有效的,所以我相信我的问题都与PHP文件有关,但是我已经发布了我已经完成的java代码。在另一个问题中,我将发布PHP代码 try { httpclient = new default HttpClient(); httppost = new HttpPost(""); nameValuePair = new a

基本上,我已经在数据库端设置了一些成员,我还做了一个注册表,它将数据发布到数据库中,但我遇到的问题是,我的程序不会启动活动。当我注释掉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();
}
试试看
{
httpclient=新的默认httpclient();
httppost=新的httppost(“”);
nameValuePair=新阵列列表(1);
添加(新的BasicNameValuePair(“email”,email.getText().toString().trim());
添加(新的BasicNameValuePair(“密码”,password.getText().toString().trim());
setEntity(新的UrlEncodedF或mEntity(nameValuePair));
response=httpclient.execute(httppost);
ResponseHandlerResponseHandler=new BasicResponseHandler();
final-Stringresponse=httpclient.execute(httppost,responseHandler);
loginerrormg.setText(“+响应);
if(response.equalsIgnorecase(“登录成功”))
{
startActivity(新意图(LoginActivity.this,HomescreenActivity.class));
}
}
捕获(例外一)
{
e、 printStackTrace();
}

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

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


请参阅本教程。

您是否申请了Internet权限

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

nameValuePair=newarraylist(1);
添加(新的BasicNameValuePair(“email”,email.getText().toString().trim());
添加(新的BasicNameValuePair(“密码”,password.getText().toString().trim());
setEntity(新的UrlEncodedFormEntity(nameValuePair));
response=httpclient.execute(httppost);
ResponseHandler ResponseHandler=新BasicResponseHandler();
最终HttpResponse responsed=httpclient.execute(httppost,responseHandler);
最终字符串响应=EntityUtils.toString(responsed.getEntity());
loginerrormg.setText(“+响应);
if(response.equalsIgnoreCase(“登录成功”))
startActivity(新意图(LoginActivity.this、HomescreenActivity.class));
}
捕获(例外e){
e、 printStackTrace();
}

显示完整堆栈跟踪。感谢您的回复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):确保在分配另一个连接之前释放连接。谢谢你的回复,我会尝试一下,然后再给你回复。谢谢你是的,我做完了。当我的注册表表单将数据发布到数据库时,它连接到数据库。它只是不启动活动。我认为这与我的PHP文件有关。非常感谢。
    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();
}