Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Sending data to be stored in MySQL
    primarykey
    data
    text
    <p><strong>Solved:</strong> Was missing view parameter for postData(), changed to reflect this.</p> <p>I would like some help with sending GPS data to a server which will be stored in a MySQL database using PHP.</p> <p>This is inside my Java file:</p> <pre><code>ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2); public void postData(View v) { nameValuePairs.add(new BasicNameValuePair("Lat","19.80")); nameValuePairs.add(new BasicNameValuePair("Lon","13.22")); //http post try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.xxxxxxxx.com/test.php"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); Log.i("postData", response.getStatusLine().toString()); } catch(Exception e) { Log.e("log_tag", "Error in http connection "+e.toString()); } } </code></pre> <p>And my PHP:</p> <pre><code>&lt;?php include 'connect.php'; //Connect //retrieve the data $lat = $_POST['lat']; $lon = $_POST['lon']; $sql = "INSERT INTO Coords (Lat, Lon) VALUES('$lat', '$lon')"; if (!mysql_query($sql, $sqlCon)) { die('Error: ' . mysql_error()); } else { //echo "1 record added"; } include 'closeConnection.php'; ?&gt; </code></pre> <p>StackTrace: Project - Heat [Android Application]</p> <pre><code> 02-06 00:37:14.265: ERROR/AndroidRuntime(1607): FATAL EXCEPTION: main 02-06 00:37:14.265: ERROR/AndroidRuntime(1607): java.lang.IllegalStateException: Could not find a method **postData(View)** in the activity class com.nathanhunston.heat.Main for onClick handler on view class android.widget.Button with id 'dropLocBtn' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload