Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:15:18+00:00 2026-06-12T23:15:18+00:00

I ran into a problem when trying to parse XML from a URL in

  • 0

I ran into a problem when trying to parse XML from a URL in the method doInBackground of class AsyncTask. What is most interesting before it worked but after some of my changes (now parses the link). I checked – the link nourish correct XML. The parser parses the response links at some point, but generates a fatal error. I hope very much for your help.

//analized DB & create var arrays with info about markers
        @Override
        protected Void doInBackground(Void ... param) {

            setButtonsClickListener();

            needShowLocation = 
                saxParserGetLocationRate.getIdAndRate(myLocationLatitudeDouble, myLocationLongitudeDouble);

        createArrayMarkersPlace();

        return null;
    }

PARSER CLASS

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;
}

LOG

"$ 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 "
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:15:19+00:00Added an answer on June 12, 2026 at 11:15 pm

    You’re adding objects to needShowLoactionId and needShowLoactionRate when they are null. In startElement:

    needShowLoactionId.add(q);
    ...
    needShowLoactionRate.add(Float.valueOf((atmosphearRating + peoplemeterRating)/2));
    

    The stack-trace shows the Exception cause is a NullPointerException, occuring in SAXParserGetLocationRate$1.startElement (on line 54). (The “$1” means the startElement method occurs in the first anonymous inner class inside SAXParseGetLocationRate–in this case DefaultHandler.)

    To fix this, change these lines:

    private ArrayList<Integer> needShowLoactionId;
    private ArrayList<Float> needShowLoactionRate;
    

    … to something like this:

    private ArrayList<Integer> needShowLoactionId = new ArrayList<Integer>();
    private ArrayList<Float> needShowLoactionRate = new ArrayList<Float>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem while trying to parse an XML string returned from
I ran into a problem trying to remove a row from a datatable in
I ran into a problem today trying to override an implementation of an interface
I'm messing around with template specialization and I ran into a problem with trying
I just ran into a problem.. I'm trying to build a website at the
I was practising statements and ran into a problem. I'm trying to make it
I'm trying to extend JButton with Clojure, but I ran into a problem when
While trying out an experimental UINavigationController-based iPhone application, I ran into a problem when
A problem I recently ran into was that when trying to update a field
We have a website and we just ran into a problem when trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.