由网友(裝不出、幸福)分享简介:解决:失踪了POSTDATA视图参数(),更改以反映这种我想一些帮助,发送GPS数据,这些数据将被存储在MySQL数据库中使用PHP的服务器。这是在我的Java文件:的ArrayList<的NameValuePair> namevaluepairs中=新的ArrayList<的NameValuePa...![如何将excel表格的数据导入到mysql数据中去](https://p.xsw88.cn/allimgs/daicuo/20230905/2276.png)
解决:失踪了POSTDATA视图参数(),更改以反映这种
我想一些帮助,发送GPS数据,这些数据将被存储在MySQL数据库中使用PHP的服务器。
这是在我的Java文件:
的ArrayList<的NameValuePair> namevaluepairs中=新的ArrayList<的NameValuePair>(2);
公共无效POSTDATA(视图v)
{
nameValuePairs.add(新BasicNameValuePair(纬度,19.80));
nameValuePairs.add(新BasicNameValuePair(经度,13.22));
// HTTP POST
尝试{
HttpClient的HttpClient的=新DefaultHttpClient();
HttpPost httppost =新
HttpPost(http://www.xxxxxxxx.com/test.php);
httppost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));
HTT presponse响应= httpclient.execute(httppost);
HttpEntity实体= response.getEntity();
InputStream的是= entity.getContent();
Log.i(POSTDATA,response.getStatusLine()的toString());
}
赶上(例外五)
{
Log.e(log_tag,错误的HTTP连接+ e.toString());
}
}
和我的PHP:
< PHP
包括将connect.php; //连接
//检索数据
$经纬度= $ _ POST ['纬度'];
$ LON = $ _ POST ['LON'];
$ SQL =INSERT INTO COORDS(纬度,经度)VALUES('$纬度','$ LON');
如果(!的mysql_query($的SQL,$ sqlCon))
{
死亡(错误:mysql_error());
}
其他
{
//回声1纪录补充;
}
包括closeConnection.php;
?>
![如何将excel表格的数据导入到mysql数据中去](https://p.xsw88.cn/allimgs/daicuo/20230905/2276.png)
堆栈跟踪: 项目 - 热火[Android应用程序]
02-06 00:37:14.265:ERROR / AndroidRuntime(1607):致命异常:主要
02-06 00:37:14.265:ERROR / AndroidRuntime(1607):java.lang.IllegalStateException:可能
没有找到一个方法** POSTDATA(查看)**在活动课com.nathanhunston.heat.Main为
在视图类android.widget.Button onclick处理程序ID为'dropLocBtn
解决方案
你的堆栈跟踪的第一行会告诉你到底你做错了什么:
02-06 00:37:14.265:ERROR / AndroidRuntime(1607):致命异常:主要
02-06 00:37:14.265:ERROR / AndroidRuntime(1607):java.lang.IllegalStateException:找不到在活动课com.nathanhunston.heat.Main对视图类的android onclick处理方法POSTDATA(查看)。 widget.Button ID为'dropLocBtn
那是因为你没有在你的 POSTDATA()
方法声明中的查看
参数。
Solved: Was missing view parameter for postData(), changed to reflect this.
I would like some help with sending GPS data to a server which will be stored in a MySQL database using PHP.
This is inside my Java file:
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(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());
}
}
And my PHP:
<?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';
?>
StackTrace: Project - Heat [Android Application]
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'
解决方案
The first line of your stack trace tells you exactly what you are doing wrong:
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'
That is because you do not have a View
parameter in your postData()
method declaration.
相关推荐
最新文章