- 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/
使用Suitecrm 7.9.1 每当我尝试创建销售线索时(即提交创建销售线索表格后),我都会遇到以下错误。 每当我尝试导入csv文件时,都会遇到相同的错误。仅在实时服务器上发生此错误 Fatal e
Closed. This question is not reproducible or was caused by typos。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-to
我想在QNX上运行GoogleTestLibrary吗? 但是我收到此错误消息? ldd:FATAL: Could not load library libgtest.so.0 首先,我使用make命
尝试编译代码时,IDE 中显示的 fatal error 和非 fatal error 之间的主要区别是什么? 在这两种情况下,编译器都会显示一条错误消息,并且不会编译程序。 fatal error
当一个人试图编译代码时,在 IDE 中显示的 fatal error 和非 fatal error 之间的主要区别是什么? 在这两种情况下,编译器都会显示一条错误消息,并且程序不会被编译。 fatal
这个程序发出app: 2015/10/24 11:28:15 example.go:22: open some-crazy-non-existent-file: no such file or dir
因此,我正在从事一个项目,但是由于不断收到错误和警告,所以我遇到了一个问题。我对PHP还是很陌生,所以要保持柔和。使用PHP 5.5可以正常运行该程序。但是,当我在PHP 5.6中运行该程序时,会收到
在 WiX 安装程序中 - 如何自定义或覆盖 fatal error 对话框 ()?我想显示详细的错误消息而不是默认设置失败消息。 选项: 是否可以在 WiX 中调整 fatal error 对话框的
我正在尝试通过 Android 工具 > 重命名应用程序包 在 eclipse 中重命名我的 android 应用程序包。它正在生成错误说 A Fatal error occurred while p
我正在使用 Ubuntu 13.10 x64,我正在做一些开发人员正在使用 Windows 的项目,我最近将 git config core.eol 更改为“lf”和 core .autocrlf 为
嗯..世界上的每个服务都可以连接到我的动物园管理员,除了 kafka。下面是我在 server.properties 文件中的连接字符串 zk.connect=1.dzk.syd.druid.neo.
我正在 Java EE 7 中尝试一些东西,我已经构建了一个示例应用程序,可以在此处找到 https://github.com/kenparker/moviplex7.git . 在此过程中,我了解到
我正在尝试使用 bitbucket 中的 ssh 克隆我的存储库,但是每当我克隆存储库时,我都会得到: Connection to bitbucket.org closed by remote hos
该代码包括从一系列数字创建一个数组,以及第三个参数,其中它指示数字的步长,如果它的步长为 2,例如它来自 [1,3, 5] 代码工作正常,除非我以负数作为参数传递 step,例如NumberRange
我正在尝试在我的 ubuntu 中运行一个简单的 git pull 命令。直到几天前,它还可以完美地工作。不是它显示致命:无法访问“https://xxxxxx@bitbucket.org/repon
我知道已经有人问过类似的问题。 但是,我认为我的问题是由于我之前犯的一个错误,因此有所不同:让我解释一下。 一切都如我所愿顺利进行: git add . 我本地存储库中的所有文件。 git commi
我在尝试执行 Jenkins 作业时看到错误。 git 版本 1.8.3.1 Jenkins 2.46.2.1-滚动 我尝试将 git 升级到更高版本,但仍然通过关注 How to install l
Image of the output in the browser 我正在离线处理一个项目。我有一个名为 index.php 的文件。 现在我想在可以编辑的浏览器 sp 中启动。 但是当我尝试通过
我正在AWS的Linux机器上运行RServer Studio。 我尝试安装ModelMetrics的依赖项caret,并收到此错误: auc_.cpp:2:10: fatal error: omp.
我似乎没有重复发帖,所以这是详细信息... 当我使用 XOM(XML 对象模型,Java 库)中的非静态方法 Builder.build() 解析文档时,在 Eclipse 控制台中我得到: [Fat
我是一名优秀的程序员,十分优秀!