- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试从 AsyncTask
类的 doInBackground
方法中的 URL 解析 XML
时遇到了问题。在它起作用之前但在我进行一些更改之后(现在解析链接),最有趣的是。我检查过 - 链接提供了正确的 XML。解析器在某个时刻解析响应链接,但会生成 fatal error 。非常希望得到您的帮助。
//analized DB & create var arrays with info about markers
@Override
protected Void doInBackground(Void ... param) {
setButtonsClickListener();
needShowLocation =
saxParserGetLocationRate.getIdAndRate(myLocationLatitudeDouble, myLocationLongitudeDouble);
createArrayMarkersPlace();
return null;
}
解析器类
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import android.util.Log;
import android.widget.Toast;
public class SAXParserGetLocationRate {
//Обработчик событий парсера
DefaultHandler handler = new DefaultHandler() {
//Метод для отслеживания старта разбора документа
@Override
public void startDocument() {
Log.d("SAXParser", "start document");
}
// Метод для отслеживание конца разбора документа
@Override
public void endDocument()
{
needShowLocation = new NeedShowLocation(needShowLoactionId, needShowLoactionRate);
status = false;
flag = false;
Log.d("SAXParser", "end document");
}
//Метод для отслеживание открываемых тегов и их атрибутов
@Override
public void startElement(String uri, String lname, String qname, Attributes attr) {
if(lname.equals("status"))status = true;
Log.d("uri/lname/qname/attr/flagStatus", uri+"/"+lname+"/"+qname+"/"+attr.getLength()+"/"+flag);
if(lname.equals("object") && flag){
Log.d("/", "/");
for(int i=0;i<attr.getLength();i++){
Log.d("*", "*");
if(i==0){
Log.d("-", "-");
Integer q = Integer.valueOf(attr.getValue(i));
Log.d("+", "+");
needShowLoactionId.add(q);
Log.d("needShowLoactionId.add", Integer.valueOf(attr.getValue(i))+"");
}
if(i==1){
atmosphearRating = Integer.valueOf(attr.getValue(i));
}
if(i==2){
peoplemeterRating = Integer.valueOf(attr.getValue(i));
needShowLoactionRate.add(Float.valueOf((atmosphearRating + peoplemeterRating)/2));
Log.d("needShowLoactionRate.add", ((atmosphearRating + peoplemeterRating)/2)+"");
}
}
}
}
// Метод для отслеживания конца документа
@Override
public void endElement(String uri, String lname, String qname) {
//
}
// Метод для изьятия символьных даных тегов
@Override
public void characters (char[] data, int start, int lenght) throws SAXException {
super.characters(data, start, lenght); // вызов метода с предыдущей реализацией
StringBuilder lineBuilder = new StringBuilder(); // создани экземпляра класа для формирования строки
lineBuilder.append(data, start, lenght); //формирование строки на основе масива символов, откуда изымаються элементы в количестве lenght начиная с элемента start
String line = lineBuilder.toString().trim(); //создание строки с усеканием пробелов в начале и конце
if(!(line.length()==0)) // условие проверяет не пустая ли строка
{
if(status && line.equals("ok")){
flag = true;
status = false;
Log.d("need show location", line);
}
if(status && line.equals("error")){
this.endDocument();
Log.d("need show location", line);
}
}
}
};
public NeedShowLocation getIdAndRate(double latitude, double longitude) {
Log.d("latitude/longitude", latitude+"/"+longitude);
SAXParserFactory factory = SAXParserFactory.newInstance(); // создание класа-фабрики для парсера
factory.setNamespaceAware(true); //установка подержки пронстрансва имён
try {
saxParser = factory.newSAXParser(); //создание класа парсера
} catch (ParserConfigurationException e1) {
System.out.println("ParserConfigurationException "+e1);
} catch (SAXException e1) {
System.out.println("SAXException "+e1);
}
Log.d("source_parse", "http://&&&.&&&.&&&/places_data/?lat="+latitude+"&lng="+longitude);
try {
saxParser.parse("http://&&&.&&&.&&&/places_data/?lat="+latitude+"&lng="+longitude, handler);
} catch (SAXException e) {
System.out.println("SAXException "+e);
} catch (IOException e) {
System.out.println("IOException "+e);
}
return needShowLocation;
}
private NeedShowLocation needShowLocation = null;
private SAXParser saxParser;
private ArrayList<Integer> needShowLoactionId;
private ArrayList<Float> needShowLoactionRate;
private int atmosphearRating;
private int peoplemeterRating;
private boolean status = false;
private boolean flag = false;
}
日志
"$ 10-17 15:51:57.999: D/Facebook-Util(13671): GET URL: https://graph.facebook.com/me?access_token=AAAFGvgaKHNgBAJdQwSkb5j1hXG8b61RitnEjIW3vpiMnemIIDYh1lA9LDz9BNx9NZAp5sCoDqIDfRygPL7eHtlhtY50TTJZCWDiybn1QZDZD&format=json 10-17 15:51:58.639: D/dalvikvm(13671): GC_CONCURRENT freed 228K, 49% free 2884K/5639K, external 611K/1112K, paused 8ms+10ms 10-17 15:51:58.989: D/Expir.onPause()(13671): START 10-17 15:51:58.989: D/Expir.onPause()(13671): FINISH 10-17 15:51:59.389: D/dalvikvm(13671): GC_CONCURRENT freed 306K, 48% free 3112K/5895K, external 611K/1112K, paused 9ms+7ms 10-17 15:51:59.479: D/onCreate()(13671): START 10-17 15:51:59.639: D/dalvikvm(13671): GC_CONCURRENT freed 537K, 50% free 3134K/6151K, external 611K/1112K, paused 4ms+10ms 10-17 15:51:59.829: D/dalvikvm(13671): GC_CONCURRENT freed 381K, 47% free 3265K/6151K, external 673K/1112K, paused 4ms+5ms 10-17 15:52:00.039: D/dalvikvm(13671): GC_CONCURRENT freed 519K, 48% free 3279K/6279K, external 673K/1112K, paused 4ms+6ms 10-17 15:52:00.199: D/dalvikvm(13671): GC_CONCURRENT freed 329K, 45% free 3462K/6279K, external 673K/1112K, paused 5ms+5ms 10-17 15:52:00.369: D/szipinf(13671): Initializing inflate state 10-17 15:52:00.469: D/onCreate()(13671): FINISH 10-17 15:52:00.469: D/onStart()(13671): START 10-17 15:52:00.469: D/onStart()(13671): FINISH 10-17 15:52:00.469: D/onResume()(13671): START 10-17 15:52:00.479: D/onResume()(13671): FINISH 10-17 15:52:00.489: D/latitude/longitude(13671): 57.702966/11.973206 10-17 15:52:00.539: D/source_parse(13671): http://&&&.&&&.&&&/places_data/?lat=57.702966&lng=11.973206 10-17 15:52:00.599: I/MapActivity(13671): Handling network change notification:CONNECTED 10-17 15:52:00.599: E/MapActivity(13671): Couldn't get connection factory client 10-17 15:52:00.689: D/dalvikvm(13671): GC_CONCURRENT freed 558K, 49% free 3325K/6407K, external 910K/1112K, paused 4ms+9ms 10-17 15:52:00.799: D/dalvikvm(13671): GC_EXTERNAL_ALLOC freed 181K, 51% free 3144K/6407K, external 910K/1112K, paused 114ms 10-17 15:52:00.869: D/dalvikvm(13671): GC_FOR_MALLOC freed 1K, 51% free 3143K/6407K, external 1166K/1678K, paused 55ms 10-17 15:52:00.869: I/dalvikvm-heap(13671): Grow heap (frag case) to 6.693MB for 69582-byte allocation 10-17 15:52:00.929: D/dalvikvm(13671): GC_FOR_MALLOC freed <1K, 51% free 3211K/6535K, external 1166K/1678K, paused 53ms 10-17 15:52:01.029: D/dalvikvm(13671): GC_FOR_MALLOC freed 170K, 51% free 3258K/6535K, external 1166K/1678K, paused 56ms 10-17 15:52:01.139: D/dalvikvm(13671): GC_FOR_MALLOC freed 48K, 50% free 3292K/6535K, external 1166K/1678K, paused 58ms 10-17 15:52:01.139: I/dalvikvm-heap(13671): Grow heap (frag case) to 6.838MB for 69582-byte allocation 10-17 15:52:01.199: D/dalvikvm(13671): GC_FOR_MALLOC freed 63K, 51% free 3297K/6663K, external 1166K/1678K, paused 54ms 10-17 15:52:01.459: D/Expir.onStop()(13671): START 10-17 15:52:01.459: D/Expir.onStop()(13671): FINISH 10-17 15:52:01.659: D/SAXParser(13671): start document 10-17 15:52:01.659: D/uri/lname/qname/attr/flagStatus(13671): /content/content/0/false 10-17 15:52:01.659: D/uri/lname/qname/attr/flagStatus(13671): /status/status/0/false 10-17 15:52:01.659: D/need show location(13671): ok 10-17 15:52:01.659: D/uri/lname/qname/attr/flagStatus(13671): /object/object/5/true 10-17 15:52:01.659: D//(13671): / 10-17 15:52:01.659: D/*(13671): * 10-17 15:52:01.659: D/-(13671): - 10-17 15:52:01.659: D/+(13671): + 10-17 15:52:01.669: W/dalvikvm(13671): threadid=9: thread exiting with uncaught exception (group=0x40018560) 10-17 15:52:01.679: E/AndroidRuntime(13671): FATAL EXCEPTION: AsyncTask #1 10-17 15:52:01.679: E/AndroidRuntime(13671): java.lang.RuntimeException: An error occured while executing doInBackground() 10-17 15:52:01.679: E/AndroidRuntime(13671): at android.os.AsyncTask$3.done(AsyncTask.java:200) 10-17 15:52:01.679: E/AndroidRuntime(13671): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) 10-17 15:52:01.679: E/AndroidRuntime(13671): at java.util.concurrent.FutureTask.setException(FutureTask.java:125) 10-17 15:52:01.679: E/AndroidRuntime(13671): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) 10-17 15:52:01.679: E/AndroidRuntime(13671): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 10-17 15:52:01.679: E/AndroidRuntime(13671): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 10-17 15:52:01.679: E/AndroidRuntime(13671): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 10-17 15:52:01.679: E/AndroidRuntime(13671): at java.lang.Thread.run(Thread.java:1019) 10-17 15:52:01.679: E/AndroidRuntime(13671): Caused by: java.lang.NullPointerException 10-17 15:52:01.679: E/AndroidRuntime(13671): at expir.java.file.SAXParserGetLocationRate$1.startElement(SAXParserGetLocationRate.java:54) 10-17 15:52:01.679: E/AndroidRuntime(13671): at org.apache.harmony.xml.ExpatParser.startElement(ExpatParser.java:145) 10-17 15:52:01.679: E/AndroidRuntime(13671): at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method) 10-17 15:52:01.679: E/AndroidRuntime(13671): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:518) 10-17 15:52:01.679: E/AndroidRuntime(13671): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479) 10-17 15:52:01.679: E/AndroidRuntime(13671): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318) 10-17 15:52:01.679: E/AndroidRuntime(13671): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:291) 10-17 15:52:01.679: E/AndroidRuntime(13671): at javax.xml.parsers.SAXParser.parse(SAXParser.java:390) 10-17 15:52:01.679: E/AndroidRuntime(13671): at javax.xml.parsers.SAXParser.parse(SAXParser.java:266) 10-17 15:52:01.679: E/AndroidRuntime(13671): at expir.java.file.SAXParserGetLocationRate.getIdAndRate(SAXParserGetLocationRate.java:114) 10-17 15:52:01.679: E/AndroidRuntime(13671): at expir.java.file.MyMapActivity$AsyncLoader.doInBackground(MyMapActivity.java:572) 10-17 15:52:01.679: E/AndroidRuntime(13671): at expir.java.file.MyMapActivity$AsyncLoader.doInBackground(MyMapActivity.java:1) 10-17 15:52:01.679: E/AndroidRuntime(13671): at android.os.AsyncTask$2.call(AsyncTask.java:185) 10-17 15:52:01.679: E/AndroidRuntime(13671): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 10-17 15:52:01.679: E/AndroidRuntime(13671): ... 4 more 10-17 15:52:01.689: D/onPause()(13671): START 10-17 15:52:01.719: D/onPause()(13671): FINISH 10-17 15:52:01.759: D/Expir.onRestart()(13671): START 10-17 15:52:01.759: D/Expir.onRestart()(13671): FINISH 10-17 15:52:01.759: D/Expir.onStart()(13671): START 10-17 15:52:01.759: D/Expir.onStart()(13671): FINISH 10-17 15:52:01.759: D/Expir.onResume()(13671): START 10-17 15:52:01.759: D/Expir.onResume()(13671): FINISH 10-17 15:52:02.049: D/onStop()(13671): START 10-17 15:52:02.049: D/onStop()(13671): FINISH 10-17 15:52:02.049: D/onDestroy()(13671): START 10-17 15:52:02.049: D/onDestroy()(13671): FINISH 10-17 15:52:02.079: E/WindowManager(13671): Activity expir.java.file.MyMapActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@406318d8 that was originally added here 10-17 15:52:02.079: E/WindowManager(13671): android.view.WindowLeaked: Activity expir.java.file.MyMapActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@406318d8 that was originally added here 10-17 15:52:02.079: E/WindowManager(13671): at android.view.ViewRoot.<init>(ViewRoot.java:259) 10-17 15:52:02.079: E/WindowManager(13671): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 10-17 15:52:02.079: E/WindowManager(13671): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 10-17 15:52:02.079: E/WindowManager(13671): at android.view.Window$LocalWindowManager.addView(Window.java:465) 10-17 15:52:02.079: E/WindowManager(13671): at android.app.Dialog.show(Dialog.java:241) 10-17 15:52:02.079: E/WindowManager(13671): at expir.java.file.MyMapActivity$AsyncLoader.onPreExecute(MyMapActivity.java:562) 10-17 15:52:02.079: E/WindowManager(13671): at android.os.AsyncTask.execute(AsyncTask.java:391) 10-17 15:52:02.079: E/WindowManager(13671): at expir.java.file.MyMapActivity.onCreate(MyMapActivity.java:75) 10-17 15:52:02.079: E/WindowManager(13671): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 10-17 15:52:02.079: E/WindowManager(13671): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722) 10-17 15:52:02.079: E/WindowManager(13671): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784) 10-17 15:52:02.079: E/WindowManager(13671): at android.app.ActivityThread.access$1500(ActivityThread.java:123) 10-17 15:52:02.079: E/WindowManager(13671): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939) 10-17 15:52:02.079: E/WindowManager(13671): at android.os.Handler.dispatchMessage(Handler.java:99) 10-17 15:52:02.079: E/WindowManager(13671): at android.os.Looper.loop(Looper.java:130) 10-17 15:52:02.079: E/WindowManager(13671): at android.app.ActivityThread.main(ActivityThread.java:3835) 10-17 15:52:02.079: E/WindowManager(13671): at java.lang.reflect.Method.invokeNative(Native Method) 10-17 15:52:02.079: E/WindowManager(13671): at java.lang.reflect.Method.invoke(Method.java:507) 10-17 15:52:02.079: E/WindowManager(13671): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847) 10-17 15:52:02.079: E/WindowManager(13671): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605) 10-17 15:52:02.079: E/WindowManager(13671): at dalvik.system.NativeStart.main(Native Method) 10-17 15:57:01.779: I/Process(13671): Sending signal. PID: 13671 SIG: 9 "
最佳答案
当 needShowLoactionId
和 needShowLoactionRate
为 null
时,您将向它们添加对象。在startElement
中:
needShowLoactionId.add(q);
...
needShowLoactionRate.add(Float.valueOf((atmosphearRating + peoplemeterRating)/2));
堆栈跟踪显示异常原因是 NullPointerException,发生在 SAXParserGetLocationRate$1.startElement
(第 54 行)中。 (“$1”表示 startElement
方法出现在 SAXParseGetLocationRate
内的第一个匿名内部类中 - 在本例中为 DefaultHandler
。)
要解决此问题,请更改以下行:
private ArrayList<Integer> needShowLoactionId;
private ArrayList<Float> needShowLoactionRate;
...像这样:
private ArrayList<Integer> needShowLoactionId = new ArrayList<Integer>();
private ArrayList<Float> needShowLoactionRate = new ArrayList<Float>();
关于java - 在异步线程中解析时出现 fatal error (AsyncTask.doInBackground()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12935523/
我一直在使用 AJAX 从我正在创建的网络服务中解析 JSON 数组时遇到问题。我的前端是一个简单的 ajax 和 jquery 组合,用于显示从我正在创建的网络服务返回的结果。 尽管知道我的数据库查
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我在尝试运行 Android 应用程序时遇到问题并收到以下错误 java.lang.NoClassDefFoundError: com.parse.Parse 当我尝试运行该应用时。 最佳答案 在这
有什么办法可以防止etree在解析HTML内容时解析HTML实体吗? html = etree.HTML('&') html.find('.//body').text 这给了我 '&' 但我想
我有一个有点疯狂的例子,但对于那些 JavaScript 函数作用域专家来说,它看起来是一个很好的练习: (function (global) { // our module number one
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
我需要编写一个脚本来获取链接并解析链接页面的 HTML 以提取标题和其他一些数据,例如可能是简短的描述,就像您链接到 Facebook 上的内容一样。 当用户向站点添加链接时将调用它,因此在客户端启动
在 VS Code 中本地开发时,包解析为 C:/Users//AppData/Local/Microsoft/TypeScript/3.5/node_modules/@types//index而不是
我在将 json 从 php 解析为 javascript 时遇到问题 这是我的示例代码: //function MethodAjax = function (wsFile, param) {
我在将 json 从 php 解析为 javascript 时遇到问题 这是我的示例代码: //function MethodAjax = function (wsFile, param) {
我被赋予了将一种语言“翻译”成另一种语言的工作。对于使用正则表达式的简单逐行方法来说,源代码过于灵活(复杂)。我在哪里可以了解更多关于词法分析和解析器的信息? 最佳答案 如果你想对这个主题产生“情绪化
您好,我在解析此文本时遇到问题 { { { {[system1];1;1;0.612509325}; {[system2];1;
我正在为 adobe after effects 在 extendscript 中编写一些代码,最终变成了 javascript。 我有一个数组,我想只搜索单词“assemble”并返回整个 jc3_
我有这段代码: $(document).ready(function() { // }); 问题:FB_RequireFeatures block 外部的代码先于其内部的代码执行。因此 who
背景: netcore项目中有些服务是在通过中间件来通信的,比如orleans组件。它里面服务和客户端会指定网关和端口,我们只需要开放客户端给外界,服务端关闭端口。相当于去掉host,这样省掉了些
1.首先贴上我试验成功的代码 复制代码 代码如下: protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
什么是 XML? XML 指可扩展标记语言(eXtensible Markup Language),标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言。 你可以通过本站学习 X
【PHP代码】 复制代码 代码如下: $stmt = mssql_init('P__Global_Test', $conn) or die("initialize sto
在SQL查询分析器执行以下代码就可以了。 复制代码代码如下: declare @t varchar(255),@c varchar(255) declare table_cursor curs
前言 最近练习了一些前端算法题,现在做个总结,以下题目都是个人写法,并不是标准答案,如有错误欢迎指出,有对某道题有新的想法的友友也可以在评论区发表想法,互相学习🤭 题目 题目一: 二维数组中的
我是一名优秀的程序员,十分优秀!