Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Json Http请求错误_Android_Json - Fatal编程技术网

Android Json Http请求错误

Android Json Http请求错误,android,json,Android,Json,您好,我最近将两个应用程序组合在一起(单独运行时效果很好),但是当我将它们组合在一起时,我不断得到一个JSONParser.makeHttpRequest错误 (这是logcat展示的内容) 您正在主线程上调用“网络通信代码”。为此使用异步任务 使用 启动异步任务 下面是异步任务的示例 private class MyAsyncTask extends AsyncTask<String, String, String> { private HashMap<String, Str

您好,我最近将两个应用程序组合在一起(单独运行时效果很好),但是当我将它们组合在一起时,我不断得到一个JSONParser.makeHttpRequest错误

(这是logcat展示的内容)

您正在主线程上调用“网络通信代码”。为此使用异步任务

使用

启动异步任务

下面是异步任务的示例

private class MyAsyncTask extends AsyncTask<String, String, String> {
private HashMap<String, String> keyValue = new HashMap<String, String>();
protected void onPreExecute() {

    //initialise variable

    super.onPreExecute();


    keyValue.put("user_name", name);
    keyValue.put("password", password);
    }
 protected Long doInBackground(String... params) {
    // do your long running process here
         try {
        FetchUrl findLocation = new FetchUrl();
        response = findLocation.fetchUrl(url, keyValue);
    } catch (Exception e) {
        e.printStackTrace();
        StackTraceElement[] ele = e.getStackTrace();

    }
    return response;
     }
     return totalSize;
 }

 protected void onProgressUpdate(Integer... progress) {
      // publish the progress of the task
     setProgressPercent(progress[0]);
 }

 protected void onPostExecute(Long result) {
     //code here for result on main thread
 }
 }
私有类MyAsyncTask扩展了AsyncTask{
private HashMap keyValue=new HashMap();
受保护的void onPreExecute(){
//初始化变量
super.onPreExecute();
keyValue.put(“用户名”,名称);
keyValue.put(“密码”,password);
}
受保护的长doInBackground(字符串…参数){
//在这里执行长时间运行的过程
试一试{
FetchUrl findLocation=新的FetchUrl();
response=findLocation.fetchUrl(url,keyValue);
}捕获(例外e){
e、 printStackTrace();
StackTraceElement[]ele=e.getStackTrace();
}
返回响应;
}
返回总大小;
}
受保护的void onProgressUpdate(整数…进度){
//发布任务的进度
setProgressPercent(进度[0]);
}
受保护的void onPostExecute(长结果){
//此处代码用于主线程上的结果
}
}

对于获取url,请遵循

发布实际错误。对于异步任务,您可以访问
new MyAsyncTask().execute();
private class MyAsyncTask extends AsyncTask<String, String, String> {
private HashMap<String, String> keyValue = new HashMap<String, String>();
protected void onPreExecute() {

    //initialise variable

    super.onPreExecute();


    keyValue.put("user_name", name);
    keyValue.put("password", password);
    }
 protected Long doInBackground(String... params) {
    // do your long running process here
         try {
        FetchUrl findLocation = new FetchUrl();
        response = findLocation.fetchUrl(url, keyValue);
    } catch (Exception e) {
        e.printStackTrace();
        StackTraceElement[] ele = e.getStackTrace();

    }
    return response;
     }
     return totalSize;
 }

 protected void onProgressUpdate(Integer... progress) {
      // publish the progress of the task
     setProgressPercent(progress[0]);
 }

 protected void onPostExecute(Long result) {
     //code here for result on main thread
 }
 }