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

  • Home
  • SEARCH
  • 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 7050021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:05:33+00:00 2026-05-28T03:05:33+00:00

I have a service which i use to parse xml data (with sax) after

  • 0

I have a service which i use to parse xml data (with sax) after what i want to start an activity to show the data parsed using an intent. But every time i launch the activity my service crashes, so i removed the intent and put a toast instead==> the service works fine. But i really need to start the activity from the service to make a query with xml rpc. My little finger tells me that it has something to do with context but i don’t know anything about context.

Here is my service: (the problem lies with the intent1)

 package tfe.rma.ciss.be;

import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class ParseFunction  extends Service{
    Server monServer;
    public String streamTitle = "",path="";
    public void onCreate() {

        Log.d("ParseFunction", ">>>onCreate()");

    }

    @Override
    public void onStart (Intent intent, int startId) {
        Log.d("ParseFunction", ">>>Started()"); 
        if (!mydata.equals("")){
         try {

             // URL rssUrl = new URL("http://thibault-koprowski.fr/feed");
              SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
              SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
              XMLReader myXMLReader = mySAXParser.getXMLReader();
              RSSHandler myRSSHandler = new RSSHandler();
              myXMLReader.setContentHandler(myRSSHandler);
              InputSource input = new InputSource(new StringReader(monServer.myData));
              myXMLReader.parse(input);
              Log.d("ParseFunction", ">>>my data is parsed()" + streamTitle );

             } catch (MalformedURLException e) {
                 Log.d("ParseFunction", ">>>exception()");  
              // TODO Auto-generated catch block
              e.printStackTrace();
              Log.d("ParseFunction", ">>>exception()");
             } catch (ParserConfigurationException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              Log.d("ParseFunction", ">>>exception()");
             } catch (SAXException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              Log.d("ParseFunction", ">>>exception()");
             } catch (IOException e) {
                 Log.d("ParseFunction", ">>>exception()");
              // TODO Auto-generated catch block
              e.printStackTrace();

             }
        }
        else {}
        if (!streamTitle.equals("")) {
            Log.d("ParseFunction", ">>>splitting streamTitle"); 
            try {
             String delims = "[\n]+" ;
                String[] tokens = streamTitle.split(delims) ;
                path= tokens[1];
                Log.d("ParseFunction", ">>>splitting done");

                Toast.makeText(this,path, Toast.LENGTH_SHORT).show();
                  }
            catch (Exception z) {
                Log.d("ParseFunction", ">>>splitting error" + " " + z); 

            }
        } else 
        { path="n'a pas pu parser" + "/n" + "no path found"; }

        try {

            Log.d("ParseFunction", ">>>lauching activity test but ...." );
        Intent intent1= new Intent (this, Test.class);
        intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent1.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);



        startActivity(intent1); } catch (Exception z) {

            Log.d("ParseFunction", ">>>Activity said hell no, to screw myself " + z);

        }


    }
    private class RSSHandler extends DefaultHandler
      {
       final int stateUnknown = 0;
       final int stateTitle = 1;
       int state = stateUnknown;

       int numberOfTitle = 0;
       String strTitle = "";
       String strElement = "";

     @Override
     public void startDocument() throws SAXException {
      // TODO Auto-generated method stub

     }

     @Override
     public void endDocument() throws SAXException {
      // TODO Auto-generated method stub

      streamTitle =  strTitle;
     }

     @Override
     public void startElement(String uri, String localName, String qName,
       Attributes attributes) throws SAXException {
      // TODO Auto-generated method stub
      if (localName.equalsIgnoreCase("sensorType"))
      {
       state = stateTitle;
       strElement = "";
       numberOfTitle++;
      }
      else if (localName.equalsIgnoreCase("imagePath"))
      {
       state = stateTitle;
       strElement = "";
       numberOfTitle++;
      }
      else if (localName.equalsIgnoreCase("numThreats"))
      {
       state = stateTitle;
       strElement = "";
       numberOfTitle++;
      }

      else if (localName.equalsIgnoreCase("latitude"))
      {
       state = stateTitle;
       strElement = "";
       numberOfTitle++;
      }
      else if (localName.equalsIgnoreCase("longitude"))
      {
       state = stateTitle;
       strElement = "";
       numberOfTitle++;
      }
      else
      {
       state = stateUnknown;
      }
     }

     @Override
     public void endElement(String uri, String localName, String qName)
       throws SAXException {
      // TODO Auto-generated method stub
      if (localName.equalsIgnoreCase("sensorType"))
      {
       strTitle += strElement + "\n";
      }
      else if (localName.equalsIgnoreCase("imagePath"))
      {
       strTitle += strElement + "\n";
      }
      else if (localName.equalsIgnoreCase("numThreats"))
      {
       strTitle += strElement + "\n";
      }

      else if (localName.equalsIgnoreCase("latitude"))
      {
       strTitle += strElement + "\n";
      }
      else if (localName.equalsIgnoreCase("longitude"))
      {
       strTitle += strElement + "\n";
      }

      else {
      state = stateUnknown;}
     }

     @Override
     public void characters(char[] ch, int start, int length)
       throws SAXException {
      // TODO Auto-generated method stub
      String strCharacters = new String(ch, start, length);
      if (state == stateTitle)
      {
       strElement += strCharacters;
      }
     }

      }
    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }
     public static String mydata = "<AvailableImageMsg><imageData><imageId>1234</imageId><sensorType>2</sensorType><imagePath>http://localhost/some/path</imagePath><timeStamp>2011-10-12T12:36:20</timeStamp></imageData><numThreats>3</numThreats><threatList><ThreadPixelDataType><threatData><threatId>3456</threatId><latitude>50.1234</latitude><longitude>4.5678</longitude><altitude>10.1</altitude><threatType>pepe</threatType><timestamp>2011-10-12T12:36:20</timestamp><threatLevel>70</threatLevel></threatData><Rectangle><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType></Rectangle></ThreadPixelDataType></threatList><threatList><ThreadPixelDataType><threatData><threatId>3457</threatId><latitude>50.1234</latitude><longitude>4.5678</longitude><altitude>10.1</altitude><threatType>pepe</threatType><timestamp>2011-10-12T12:36:20</timestamp><threatLevel>70</threatLevel></threatData><Rectangle><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType></Rectangle></ThreadPixelDataType></threatList><threatList><ThreadPixelDataType><threatData><threatId>3458</threatId><latitude>50.1234</latitude><longitude>4.5678</longitude><altitude>10.1</altitude><threatType>pepe</threatType><timestamp>2011-10-12T12:36:20</timestamp><threatLevel>70</threatLevel></threatData><Rectangle><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType><PixelCoordinatesType><x>100</x><y>200</y></PixelCoordinatesType></Rectangle></ThreadPixelDataType></threatList></AvailableImageMsg>";


}

Here is my simple activity named test

package tfe.rma.ciss.be;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class Test extends Activity{

    ParseFunction parser; 

    @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.test);

          TextView result = (TextView)findViewById(R.id.result);




          result.setText(parser.path);}



}

can someone help me please?????!

Logcat report

01-12 13:42:18.069 I/ActivityManager(  160): Start proc tfe.rma.ciss.be for service tfe.rma.ciss.be/.ParseFunction: pid=1576 uid=10065 gids={3003, 1015}
01-12 13:42:18.189 D/ParseFunction( 1576): >>>onCreate()
01-12 13:42:18.189 D/ParseFunction( 1576): >>>Started()
01-12 13:42:18.189 D/AndroidRuntime( 1576): Shutting down VM
01-12 13:42:18.189 W/dalvikvm( 1576): threadid=1: thread exiting with uncaught exception (group=0x40018578)
01-12 13:42:18.199 E/        (  160): Dumpstate > /data/log/dumpstate_app_error
01-12 13:42:18.199 E/AndroidRuntime( 1576): FATAL EXCEPTION: main
01-12 13:42:18.199 E/AndroidRuntime( 1576): java.lang.RuntimeException: Unable to start service tfe.rma.ciss.be.ParseFunction@4051ecc8 with Intent { cmp=tfe.rma.ciss.be/.ParseFunction }: java.lang.NullPointerException
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2056)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at android.app.ActivityThread.access$2800(ActivityThread.java:117)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:998)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at android.os.Looper.loop(Looper.java:123)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at android.app.ActivityThread.main(ActivityThread.java:3687)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at java.lang.reflect.Method.invokeNative(Native Method)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at java.lang.reflect.Method.invoke(Method.java:507)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at dalvik.system.NativeStart.main(Native Method)
01-12 13:42:18.199 E/AndroidRuntime( 1576): Caused by: java.lang.NullPointerException
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at tfe.rma.ciss.be.ParseFunction.onStart(ParseFunction.java:45)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at android.app.Service.onStartCommand(Service.java:428)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2043)
01-12 13:42:18.199 E/AndroidRuntime( 1576):     ... 10 more
01-12 13:42:20.709 D/BatteryService(  160): update start
01-12 13:42:20.709 D/BatteryService(  160): update start
01-12 13:42:20.709 D/BatteryService(  160): update start
01-12 13:42:22.079 D/VoldCmdListener(   87): asec list
01-12 13:42:22.089 D/VoldCmdListener(   87): CommandListener::AsecCmd::runCommand -> com.aldiko.android-1
01-12 13:42:22.089 D/VoldCmdListener(   87): CommandListener::AsecCmd::runCommand -> com.citc.ud-1
01-12 13:42:22.089 D/VoldCmdListener(   87): CommandListener::AsecCmd::runCommand -> com.creativemobile.DragRacing-1
  • 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-05-28T03:05:34+00:00Added an answer on May 28, 2026 at 3:05 am
    Intent intent1= new Intent (this, Test.class);
    intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    

    In the last line you’re referring to intent rather than intent1. Have you got another field named intent somewhere which you haven’t initialized?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have web service, which use integrated security in IIS. Now, I want to
I'm trying to parse xml from SharePoint service (lists) using jquery. I have XMLHttpRequest
I have a service which creates a number of child processes. Using c# I
Im writing an iPhone app which retrieves data from a web service as XML.
I have a service which has one endpoint , I have defined this endpoint
I have a service which takes the user supplied rich text (can have HTML
I have a web service which has a generic function that returns a dataset
I have a WCF service which will be hosted under IIS. Now I have
I have a C# service which is not an ASP.NET application, but uses a
I have a WCF service which accepts a string as a paramter for one

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.