I feel like providing you with my code is my best bet.
MAIN ACTIVITY
public class MainActivity extends ActionBarActivity {
Button submitbtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
submitbtn = (Button) findViewById(R.id.button);
submitbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
PostDataAsyncTask runner = new PostDataAsyncTask();
runner.execute();
}
});
}
OTHER METHODS AND CLASSES INSIDE MAIN ACTIVITY
PostDataAsyncTask (Unused overriden methods omitted)
public class PostDataAsyncTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... strings) {
postData();
return null;
}
}
PostData() method
private void postData(){
try{
String postReceiverUrl = "staffappfeedback.comule.com/insert-dp.php";
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(postReceiverUrl);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("name", "Mike"));
nameValuePairs.add(new BasicNameValuePair("summary", "My suggestion"));
nameValuePairs.add(new BasicNameValuePair("description", "This is what I think you should do"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
String responseStr = EntityUtils.toString(resEntity).trim();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
I have enabled internet access in the Mainifest File.
A lot of the Classes/Objects have strikethroughs on them (ie- is deprecated).
Why might this be the case?
Is this the reason my program is crashing?
My android device has issues debugging so I can't locate the problem easily, hence the post on Stack Overflow, but don't get me wrong, I have spent ages trying to find the problem.
Any ideas?
I changed postData() to
private void postData(){
try{
String postReceiverUrl = "http://staffappfeedback.comule.com/insert-dp.php";
HttpParams httpParameters = new BasicHttpParams();
HttpClient httpClient = new DefaultHttpClient(httpParameters);
httpClient.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
httpClient.getParams().setParameter("http.socket.timeout", 2000);
httpClient.getParams().setParameter("http.protocol.content-charset", HTTP.UTF_8);
httpParameters.setBooleanParameter("http.protocol.expect-continue", false);
HttpPost httpPost = new HttpPost(postReceiverUrl);
httpPost.getParams().setParameter("http.socket.timeout", 5000);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", "Mike"));
nameValuePairs.add(new BasicNameValuePair("summary", "My suggestion"));
nameValuePairs.add(new BasicNameValuePair("description", "This is what I think you should do"));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8);
httpPost.setEntity(formEntity);
HttpResponse response = httpClient.execute(httpPost);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
while ((line = in.readLine()) != null) {
sb.append(line);
}
in.close();
String result = sb.toString();
Log.e("result", result);
//HttpEntity resEntity = response.getEntity();
//if (resEntity != null) {
//String responseStr = EntityUtils.toString(resEntity).trim();
//}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
and log response from server is
06-21 14:34:59.325: E/result(3794): Error: INSERT INTO comments VALUES (NULL, android, android test, this is an android test)<br>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'test, this is an android test)' at line 1
Problem is in addition to change line String postReceiverUrl = " http://staffappfeedback.comule.com/insert-dp.php "; with your PHP script.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.