- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个应用程序,其中多个用户将其当前位置发送到远程 MySQL 数据库,然后每个用户可以拉出经纬度坐标以查看 map 上的所有用户。我目前遇到的问题是,当我尝试将我的位置发送到 MySQL 数据库时,我的应用程序崩溃了。任何帮助将不胜感激。这是我的 java Activity :
package com.paul.locations;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import com.paul.locations.JSONParser;
import com.paul.locations.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Location extends Activity implements OnClickListener {
private GoogleMap googlemap;
private String lat="", lon="", current = "";
private Button bLoad, bStore;
// Progress Dialog
private ProgressDialog pDialog;
// JSON parser class
JSONParser jsonParser = new JSONParser();
//php add a comment script
//localhost :
//testing on your device
//put your local ip instead, on windows, run CMD > ipconfig
//or in mac's terminal type ifconfig and look for the ip under en0 or en1
private static final String LOAD_INFO_URL = "http://192.168.1.14/locations/load_info.php";
private static final String UPDATE_INFO_URL = "http://192.168.1.14/locations/update_info.php";
//testing on Emulator:
//private static final String POST_COMMENT_URL = "http://10.0.2.2:1234/webservice/addcomment.php";
//testing from a real server:
//private static final String POST_COMMENT_URL = "http://www.mybringback.com/webservice/addcomment.php";
//ids
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
setUpMap();
bLoad = (Button)findViewById(R.id.bLoad);
bLoad.setOnClickListener(this);
bStore = (Button)findViewById(R.id.bStore);
bStore.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bLoad:
new AttemptLoad().execute();
break;
case R.id.bStore:
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
android.location.Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
lon = Double.toString(location.getLongitude());
lat = Double.toString(location.getLatitude());
System.out.println(lon + ", " + lat);
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
current = df.format(c.getTime());
System.out.println(current);
new AttemptStore().execute();
break;
default:
break;
}
}
class AttemptLoad extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Location.this);
pDialog.setMessage("Attempting to load locations...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
return null;
}
}
class AttemptStore extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Location.this);
pDialog.setMessage("Attempting to store your location...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
String success;
try {
// Building Parameters
List<NameValuePair> params1 = new ArrayList<NameValuePair>();
params1.add(new BasicNameValuePair("lat", lat));
params1.add(new BasicNameValuePair("lon", lon));
params1.add(new BasicNameValuePair("time", current));
Log.d("request!", "starting");
//Posting user data to script
JSONObject json = jsonParser.makeHttpRequest(
UPDATE_INFO_URL, "POST", params1);
// full json response
Log.d("Store location attempt", json.toString());
// json success element
success = json.getString(TAG_SUCCESS);
if(success.equals("SUCCESS")) {
Log.d("Location Stored!", json.toString());
finish();
return json.getString(TAG_MESSAGE);
}else{
Log.d("Storing Location Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
//if (file_url != null){
//Toast.makeText(Location.this, file_url, Toast.LENGTH_LONG).show();
//}
}
}
private void setUpMap() {
if(googlemap == null){
googlemap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
if(googlemap != null){
//code to initialize the map
googlemap.setMyLocationEnabled(true);
}
}
}
}
我相当确定错误发生在“尝试存储”类中,因为单击 bStore 按钮会创建错误
这是日志猫:
07-31 13:27:40.245: D/SensorManager(30830): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41d55290
07-31 13:27:40.245: I/SensorManager(30830): Set normal delay = true
07-31 13:27:40.245: D/SensorManager(30830): registerListener :: handle = 4 name= MPL accel delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41d58410
07-31 13:27:40.255: W/IInputConnectionWrapper(30830): getSelectedText on inactive InputConnection
07-31 13:27:40.265: W/IInputConnectionWrapper(30830): setComposingText on inactive InputConnection
07-31 13:27:43.779: D/request!(30830): starting
07-31 13:27:43.799: I/Adreno200-EGLSUB(30830): <ConfigWindowMatch:2087>: Format RGBA_8888.
07-31 13:27:43.829: D/SensorManager(30830): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41d58410
07-31 13:27:43.829: I/SensorManager(30830): Set normal delay = true
07-31 13:27:45.241: D/Login attempt(30830): {"message":"Login successful!","success":1}
07-31 13:27:45.241: D/Login Successful!(30830): {"message":"Login successful!","success":1}
07-31 13:27:45.661: D/AbsListView(30830): Get MotionRecognitionManager
07-31 13:27:45.771: I/Adreno200-EGLSUB(30830): <ConfigWindowMatch:2087>: Format RGBA_8888.
07-31 13:27:45.801: I/Adreno200-EGLSUB(30830): <ConfigWindowMatch:2098>: Format RGBX_8888.
07-31 13:27:45.961: W/IInputConnectionWrapper(30830): getSelectedText on inactive InputConnection
07-31 13:27:45.961: W/IInputConnectionWrapper(30830): setComposingText on inactive InputConnection
07-31 13:27:49.765: I/System.out(30830): -117.21201925, 32.75091863
07-31 13:27:49.765: I/System.out(30830): 13:27:49
07-31 13:27:49.796: D/request!(30830): starting
07-31 13:27:49.816: I/Adreno200-EGLSUB(30830): <ConfigWindowMatch:2087>: Format RGBA_8888.
07-31 13:27:50.987: E/JSON Parser(30830): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
07-31 13:27:50.987: D/Store location attempt(30830): {"message":"Login successful!","success":1}
07-31 13:27:50.987: D/Storing Location Failure!(30830): Login successful!
错误是 JSON 解析器无法解析数据。我知道我的 PHP 脚本是正确的,因为我只需将它们加载到浏览器中即可发送和接收数据。任何帮助都会非常酷
谢谢!
最佳答案
你检查一下json格式吗
你有这个错误
解析数据org.json.JSONException时出错:值
那么检查响应中是否得到 json 对象或 json 数组?
关于php - 具有多个用户位置的 Google map Android 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17978921/
这是代码片段。 请说出这种用小内存存储大数据的算法是什么。 public static void main(String[] args) { long longValue = 21474836
所以我使用 imap 从 gmail 和 outlook 接收电子邮件。 Gmail 像这样编码 =?UTF-8?B?UmU6IM69zq3OvyDOtc68zrHOuc67IG5ldyBlbWFpb
很久以前就学会了 C 代码;想用 Scheme 尝试一些新的和不同的东西。我正在尝试制作一个接受两个参数并返回两者中较大者的过程,例如 (define (larger x y) (if (> x
Azure 恢复服务保管库有两个备份配置选项 - LRS 与 GRS 这是一个有关 Azure 恢复服务保管库的问题。 当其驻留区域发生故障时,如何处理启用异地冗余的恢复服务保管库?如果未为恢复服务启
说,我有以下实体: @Entity public class A { @Id @GeneratedValue private Long id; @Embedded private
我有下一个问题。 我有下一个标准: criteria.add(Restrictions.in("entity.otherEntity", getOtherEntitiesList())); 如果我的
如果这是任何类型的重复,我会提前申请,但我找不到任何可以解决我的具体问题的内容。 这是我的程序: import java.util.Random; public class CarnivalGame{
我目前正在使用golang创建一个聚合管道,在其中使用“$ or”运算符查询文档。 结果是一堆需要分组的未分组文档,这样我就可以进入下一阶段,找到两个数据集之间的交集。 然后将其用于在单独的集合中进行
是否可以在正则表达式中创建 OR 条件。 我正在尝试查找包含此类模式的文件名列表的匹配项 第一个案例 xxxxx-hello.file 或者案例二 xxxx-hello-unasigned.file
该程序只是在用户输入行数时创建菱形的形状,因此它有 6 个 for 循环; 3 个循环创建第一个三角形,3 个循环创建另一个三角形,通过这 2 个三角形和 6 个循环,我们得到了一个菱形,这是整个程序
我有一个像这样的查询字符串 www.google.com?Department=Education & Finance&Department=Health 我有这些 li 标签,它们的查询字符串是这样
我有一个带有静态构造函数的类,我用它来读取 app.config 值。如何使用不同的配置值对类进行单元测试。我正在考虑在不同的应用程序域中运行每个测试,这样我就可以为每个测试执行静态构造函数 - 但我
我正在寻找一个可以容纳多个键的容器,如果我为其中一个键值输入保留值(例如 0),它会被视为“或”搜索。 map, int > myContainer; myContainer.insert(make_
我正在为 Web 应用程序创建数据库,并正在寻找一些建议来对可能具有多种类型的单个实体进行建模,每种类型具有不同的属性。 作为示例,假设我想为“数据源”对象创建一个关系模型。所有数据源都会有一些共享属
(1) =>CREATE TABLE T1(id BIGSERIAL PRIMARY KEY, name TEXT); CREATE TABLE (2) =>INSERT INTO T1 (name)
我不确定在使用别名时如何解决不明确的列引用。 假设有两个表,a 和 b,它们都有一个 name 列。如果我加入这两个表并为结果添加别名,我不知道如何为这两个表引用 name 列。我已经尝试了一些变体,
我的查询是: select * from table where id IN (1,5,4,3,2) 我想要的与这个顺序完全相同,不是从1...5,而是从1,5,4,3,2。我怎样才能做到这一点? 最
我正在使用 C# 代码执行动态生成的 MySQL 查询。抛出异常: CREATE TABLE dump ("@employee_OID" VARCHAR(50)); "{"You have an er
我有日期 2016-03-30T23:59:59.000000+0000。我可以知道它的格式是什么吗?因为如果我使用 yyyy-MM-dd'T'HH:mm:ss.SSS,它会抛出异常 最佳答案 Sim
我有一个示例模式,它的 SQL Fiddle 如下: http://sqlfiddle.com/#!2/6816b/2 这个 fiddle 只是根据 where 子句中的条件查询示例数据库,如下所示:
我是一名优秀的程序员,十分优秀!