【发布时间】:2016-05-25 03:54:36
【问题描述】:
错误转换结果 java.lang.NullPointerException: lock == null 解析数据 org.json.JSONException 时出错:字符 0 处的输入结束 的
谁能告诉我这是否有效?我已经将我的笔记本电脑与我的 wifi 和手机连接起来。两者都具有相同的 ipv4 地址,并且在 android 代码中我提到了该地址。我的手机如何知道与存储数据库的笔记本电脑联系?
这是我的 Android 代码 JSON 解析器
public JSONObject makeHttpRequest(String url, String method,List<NameValuePair> params) {
try {
if(method.equals("POST"))
{
DefaultHttpClient httpClient = new DefaultHttpClient();
Log.e("herehai"," "+is);
HttpPost httpPost = new HttpPost(url);
Log.e("hereiam"," "+httpPost);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);//<-----Error is here
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
Log.e("here"," "+is);
}
else if(method.equals("GET"))
{
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
Log.e("here1"," "+is);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine())!=null)
{
sb.append(line + "\n");
}
is.close();
json = sb.toString();
Log.e("errors",json);
}
catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
//return json string
return jObj;
}
谁能告诉我为什么会抛出空指针异常?
【问题讨论】:
-
这是一个android相关的问题
-
ummm android 代码在哪里?
-
好的,所以现在我的 php 很好,但是@g2o 你能告诉我这是否有效吗?我已经将我的笔记本电脑与我的 wifi 和手机连接起来。两者都具有相同的 ipv4 地址,并且在 android 代码中我提到了该地址。我的手机如何知道与存储数据库的笔记本电脑联系?
-
任何人??请回答
标签: java php android json getjson