Runnable上的NetworkOnMainThreadException(NetworkOnMainThreadException on Runnable)

我正在制作Android 4.4项目。 我有NetworkOnMainThreadException 。 以下是我的流程。

Service(sticky) -> Handler(per 5 minutes) -> Runnable -> HttpPost

Runnable不是一个单独的线程吗? 我在Runnable中使用AsyncTask吗?


I am making Android 4.4 project. I've got NetworkOnMainThreadException. Below is my process.

Service(sticky) -> Handler(per 5 minutes) -> Runnable -> HttpPost

Isn't Runnable a separate thread? Shoud I use AsyncTask in Runnable?


原文:https://stackoverflow.com/questions/22580354
2024-04-25 21:04

满意答案

你在每个loopecho结果。 这就是为什么你的js无法正确解析它的原因。 您应该echo一次(在循环结束时)。

$return_array = array();

foreach ($abc as $key => $value) {
    $temp = array();
    $temp['admin_name'] = $value['uName'];
    $temp['admin_email'] = $value['uEmail'];
    $temp['admin_ip'] = $value['ipAddress'];

    $return_array[] = $temp;
}

 echo json_encode($return_array);

You are echoing the result every loop. That is the reason why your js cant parse it correctly. You should echo it once(on the end of the loop.).

$return_array = array();

foreach ($abc as $key => $value) {
    $temp = array();
    $temp['admin_name'] = $value['uName'];
    $temp['admin_email'] = $value['uEmail'];
    $temp['admin_ip'] = $value['ipAddress'];

    $return_array[] = $temp;
}

 echo json_encode($return_array);

相关问答

更多

jQuery将不会从AJAX查询解析我的JSON(jQuery won't parse my JSON from AJAX query)

您的服务器是否将数据作为Content-Type "*/json" ? 如果没有,请相应地修改响应头。 例如,发送"application/json"会很好。 Is your server sending data as Content-Type "*/json"? If not, modify the response headers accordingly. Sending "application/json" would be fine, for example.

Jquery ajax json解析错误(Jquery ajax json Parse error)

你在每个loop中echo结果。 这就是为什么你的js无法正确解析它的原因。 您应该echo一次(在循环结束时)。 $return_array = array(); foreach ($abc as $key => $value) { $temp = array(); $temp['admin_name'] = $value['uName']; $temp['admin_email'] = $value['uEmail']; $temp['admin_ip'] =...

无法解析来自jquery Ajax Call的JSON响应(Unable to parse JSON response from jquery Ajax Call)

在使用CURL查看来自两个URL的响应之后,不起作用的那个不是jsonp响应。 这是一个json的回应。 它没有包含在json p工作所需的方法调用中。 不起作用的是 {"io":{"rec_count":12,...}} VS HNCallback({"nextId":null,...}) 看到不同? 由于原始策略相同,您将无法从任一URL获得纯json响应。 因此,您需要使用CORS(如果您控制其他域)或jsonp,就像您当前配置使用的那样,或服务器端代理。 after looking at ...

JavaScriptSerializer jQuery ajax:请求的JSON解析失败(JavaScriptSerializer jQuery ajax: Requested JSON parse failed)

如果您使用.NET作为服务器,例如ASP.NET MVC Web应用程序。 您需要在web.config或JsonConfiguration上更新服务器允许将JSON信息发送到客户端的最大值。 您可以查看本主题中的解决方案: 设置无限的JSON长度 if you're using .NET as server, for example a ASP.NET MVC Web app. You will need to update on the web.config or in your JsonCo...

请求的JSON解析在jquery ajax中失败(Requested JSON parse failed in jquery ajax)

也许你的标题有问题..尝试以下代码 response.setContentType("application/json"); i'had added this line already.My mistake was that i was not appending callback function name to my json response at the server end. By the way thanks. I got the answer. http://www.ibm.com...

在jQuery错误中解析JSON(Parse JSON in jQuery error)

您的数据是有效的JSON并且是一个数组,因此请使用index来获取数据。 所以你不需要JSON.parse $.post('ajax/name.php', { name: name }, function (data) { for (var i = 0; i < data.length; ++i) var tr = $('<tr/>'); tr.append("<td>" + data[i].ARTIST + "</td>"); tr.append(...

语法错误JSON.parse ajax.responsetext(Spring,jquery,ajax,gson)(Syntax Error JSON.parse ajax.responsetext (Spring,jquery,ajax,gson))

您需要返回json字符串而不是ModelAndView对象。 在ModelAndView对象上调用addOjbect方法时,您正在为模型添加或覆盖一个属性。 ModelAndView api 返回ModelAndView你基本上返回一个带有你想要显示的视图名的字符串,所以你返回的是一个html页面,而不是一个json对象。 你需要做的是返回一个json字符串。 所以它应该是这样的: @ResponseBody public String contentlistObjective(HttpServl...

用jquery ajax传递json对象(passing json object with jquery ajax)

dataType是指请求标头,而不是响应。 如果你没有发回有效的JSON,jQuery将不喜欢它。 你想发送JSON,但你可能想要找回别的东西。 只需删除dataType ,它应该可以正常工作,除非服务器脚本出错。 dataType refers to the request header, not the response. If you are not sending back valid JSON, jQuery won't like it. You want to send JSON, b...

使用jQuery解析JSON [2](Parse JSON with jQuery [2])

尝试这个: $.each(data, function(i,item){ alert(item.id + " " +item.subcategory); }); each()的第一个参数必须是迭代的对象。 它必须是数据(数据没有属性“对象”)。 提供的函数的第二个参数将是迭代对象的当前项。 Try this: $.each(data, function(i,item){ alert(item.id + " " +item.subcategory); }); The first ...

相关文章

更多

tomcat线程一直处于RUNNABLE,不接受请求

最近项目中一个模块出现一个问题,本人做的比较浅显,所以很简单的问题一直搞了好几天,通过各种查资料、工具 ...

Callable接口实现Java多线程

Callable是类似于Runnable的接口,实现Callable接口的类和实现Runnable的类 ...

关于Timer的问题

是这样的,我在程序里面用一个timer调用TimerTask,定时每个几个小时执行。在程序开始启动后的 ...

java线程状态详解(6种)

java线程类为:java.lang.Thread,其实现java.lang.Runnable接口。 ...

Hadoop中DataNode与NameNode之间的心跳机制

DataNode: 用于存储HDFS的数据, public class DataNode extend ...

与synchronized有关的线程同步问题的一点非常规情况

package thread; public class SyncTest implements R ...

请教:java 线程中队数据库进行操作,程序返回值显示成功,单实际未成功

问题描述: 近些天公司要让我完成一个导数的模块。我写了一个导数的类AssetImpThread 实现 ...

一个关于java数据报做的简单聊天的问题

数据只能从Client端发送到Server端,Server端发送到Client端不仅重复发送,而且Cl ...

Java 多线程编程

Java 多线程编程 Java给多线程编程提供了内置的支持。一个多线程程序包含两个或多个能并发 ...

关于Thread类中的start()方法和run()方法

引用 public void start() Causes this thread to ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本