我在第一个微调器的第一个类中有两个微调器和日期选择器我已经选择了第二个微调器上的相关库存点流的位置和选定的日期,三个字符串对象使用放置字符串发送到下一个类,获取字符串并添加到 url项目,项目 1,日期。并运行应用程序选择位置、库存点、日期,然后按获取表格按钮,它将强制关闭。我调试它,当光标到达 JSONObject json1 = jParser.getJSONFromUrl(url); 时,对象被发送并成功添加;它会关闭。当我评论 url 并替换预定义的 url 时,它将运行.. 我无法识别问题
public void torun() {
Bundle b=this.getIntent().getExtras();
String items=b.getString("item");
String items1=b.getString("item1");
String dates=b.getString("date");
// String url0 = "http://10.0.2.2:51382/RestServiceImpl.svc/json/?Location=ArihantWanarpet&GROUP=ArihantShowroom&asondate=2013-2-24";
String url = "http://10.0.2.2:51382/RestServiceImpl.svc/jsons/?Location="+items+"&GROUP="+items1+"&asondate="+dates;
// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
try {
JSONObject json1 = jParser.getJSONFromUrl(url);
// Getting Array of Contacts
JSONArray list = json1.getJSONArray(TAG_JSONDataResult);
// looping through All Contacts
for(int i = 0; i < list.length(); i++){
JSONObject c = list.getJSONObject(i);
// Storing each json item in variable
String GRPCODE = c.getString(TAG_GRPCODE);
String GRPNAME = c.getString(TAG_GRPNAME);
String QTY = c.getString(TAG_QNT);
String BUDGET = c.getString(TAG_BUDGET);
String STOCK = c.getString(TAG_STOCK);
String DIFF = c.getString(TAG_DIFF);
String DIFF_P = c.getString(TAG_DIFF_P);
String EQTY = c.getString(TAG_EQTY);
String EQTY_P = c.getString(TAG_EQTY_P);
String EBUDGET = c.getString(TAG_EBUDGET);
String ESTK = c.getString(TAG_ESTK);
String ESTK_P = c.getString(TAG_ESTK_P);
String EDIFF = c.getString(TAG_EDIFF);
String EDIFF_P = c.getString(TAG_EDIFF_P);
String DQTY = c.getString(TAG_DQTY);
String DQTY_P = c.getString(TAG_DQTY_P);
String DBUDGET = c.getString(TAG_DBUDGET);
String DSTK = c.getString(TAG_DSTK);
String DSTK_P = c.getString(TAG_DSTK_P);
String DDIFF = c.getString(TAG_DDIFF);
String DDIFF_P = c.getString(TAG_DDIFF_P);
String PQTY = c.getString(TAG_PQTY);
String PQTY_P = c.getString(TAG_PQTY_P);
String PBUDGET = c.getString(TAG_PBUDGET);
String PSTK = c.getString(TAG_PSTK);
String PSTK_P = c.getString(TAG_PSTK_P);
String PDIFF = c.getString(TAG_PDIFF);
String PDIFF_P = c.getString(TAG_PDIFF_P);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_GRPCODE, GRPCODE);
map.put(TAG_GRPNAME, GRPNAME);
map.put(TAG_QNT, QTY);
map.put(TAG_BUDGET, BUDGET);
map.put(TAG_STOCK, STOCK);
map.put(TAG_DIFF, DIFF);
map.put(TAG_DIFF_P, DIFF_P);
map.put(TAG_EQTY, EQTY);
map.put(TAG_EQTY_P, EQTY_P);
map.put(TAG_EBUDGET, EBUDGET);
map.put(TAG_ESTK, ESTK);
map.put(TAG_ESTK_P, ESTK_P);
map.put(TAG_EDIFF, EDIFF);
map.put(TAG_EDIFF_P, EDIFF_P);
map.put(TAG_DQTY, DQTY);
map.put(TAG_DQTY_P, DQTY_P);
map.put(TAG_DBUDGET, DBUDGET);
map.put(TAG_DSTK, DSTK);
map.put(TAG_DSTK_P, DSTK_P);
map.put(TAG_DDIFF, DDIFF);
map.put(TAG_DDIFF_P, DDIFF_P);
map.put(TAG_PQTY, PQTY);
map.put(TAG_PQTY_P, PQTY_P);
map.put(TAG_PBUDGET, PBUDGET);
map.put(TAG_PSTK, PSTK);
map.put(TAG_PSTK_P, PSTK_P);
map.put(TAG_PDIFF, PDIFF);
map.put(TAG_PDIFF_P, PDIFF_P);
//map.put(TAG_PHONE_MOBILE, mobile);
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.list_item,
new String[] { TAG_GRPCODE, TAG_GRPNAME, TAG_QNT, TAG_BUDGET, TAG_STOCK, TAG_DIFF, TAG_DIFF_P, TAG_EQTY, TAG_EQTY_P, TAG_EBUDGET, TAG_ESTK,
TAG_ESTK_P, TAG_EDIFF, TAG_EDIFF_P, TAG_DQTY, TAG_DQTY_P, TAG_DBUDGET, TAG_DSTK, TAG_DSTK_P, TAG_DDIFF, TAG_DDIFF_P, TAG_PQTY,
TAG_PQTY_P, TAG_PBUDGET, TAG_PSTK, TAG_PSTK_P, TAG_PDIFF, TAG_PDIFF_P },
new int[] {
R.id.l1, R.id.l2, R.id.l3, R.id.l4, R.id.l5, R.id.l6, R.id.l7, R.id.l8, R.id.l9, R.id.l10, R.id.l11, R.id.l12, R.id.l13, R.id.l14,
R.id.l15, R.id.l16, R.id.l17, R.id.l18, R.id.l19, R.id.l20, R.id.l21, R.id.l22, R.id.l23, R.id.l24, R.id.l25, R.id.l26, R.id.l27, R.id.l28, });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
// Launching new screen on Selecting Single ListItem
}
JSONParser 类
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public JSONParser() {
}
public JSONObject getJSONFromUrl(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} 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();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
日志猫
07-03 07:25:21.177 632-632/com.android.exchange E/StrictMode: null
android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d33ec0 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
at android.app.ContextImpl.bindService(ContextImpl.java:1418)
at android.app.ContextImpl.bindService(ContextImpl.java:1407)
at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
最新的 logcat 错误
07-03 07:47:04.487 1877-1877/com.androidhive.innovate E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.innovate/com.androidhive.innovate.AndroidJSONParsingActivity}: java.lang.IllegalArgumentException: Illegal character in query at index 49: http://10.0.2.2:51382/RestServiceImpl.svc/jsons/? Location=ArihantWanarpet&GROUP=ArihantShowroom&asondate=2013-7-3
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 49: http://10.0.2.2:51382/RestServiceImpl.svc/jsons/? Location=ArihantWanarpet&GROUP=ArihantShowroom&asondate=2013-7-3
at java.net.URI.create(URI.java:727)
at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
at com.androidhive.innovate.JSONParser.getJSONFromUrl(JSONParser.java:36)
at com.androidhive.innovate.AndroidJSONParsingActivity.torun(AndroidJSONParsingActivity.java:105)
at com.androidhive.innovate.AndroidJSONParsingActivity.onCreate(AndroidJSONParsingActivity.java:64)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more