can';t使用php将android应用程序连接到mysql错误与我的android代码有关
我知道我有一些错误,但我一直在改变它,不明白为什么它不会改变任何帮助将非常感谢php应该可以工作我没有从应用程序获得任何信息你不应该在主线程中调用网络连接。尝试使用AsyncTask在后台线程上运行网络操作 像这样试试can';t使用php将android应用程序连接到mysql错误与我的android代码有关,php,android,Php,Android,我知道我有一些错误,但我一直在改变它,不明白为什么它不会改变任何帮助将非常感谢php应该可以工作我没有从应用程序获得任何信息你不应该在主线程中调用网络连接。尝试使用AsyncTask在后台线程上运行网络操作 像这样试试 // httpPost.setEntity(new UrlEncodedFormEntity(nameValueParams)); HttpResponse httpResponse = httpClient.execute(httpPost);
// httpPost.setEntity(new UrlEncodedFormEntity(nameValueParams));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}});}
//@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
Intent intent = new Intent(Login.this, .class);
Login.this.startActivity(intent);
//new lister for save start db code their
//take info from button with sql
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
postData();
});
//
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
类登录扩展活动
{
创建时受保护的void(Bundle savedInstanceState)
{
button2.setOnClickListener(新的OnClickListener()
{
公共void onClick(视图arg0)
{
任务t=新任务();
t、 执行();
}
}
类任务扩展了AsyncTask以获取有关AsyncTask的更多信息。您应该将尝试联网的代码移到后台线程中。一般来说,您不应该在主(UI)线程上进行联网(从Android 3.0开始,这是完全禁止的)。
// httpPost.setEntity(new UrlEncodedFormEntity(nameValueParams));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}});}
//@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
Intent intent = new Intent(Login.this, .class);
Login.this.startActivity(intent);
//new lister for save start db code their
//take info from button with sql
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
postData();
});
//
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
Class Login extends Activity
{
protected void onCreate(Bundle savedInstanceState)
{
button2.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
Task t = new Task();
t.execute();
}
}
class Task extends AsyncTask<ArgType,ArgType,ArgType>
{
protected type doInBackground(ArgType... urls)
{
try
{
//initiate httpconnection and get result
}
catch
{
}
}
protected void onPostExecute(ArgType result)
{
//update some view or do some thing when background thread work is done
}
}
}