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 6624301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:38:08+00:00 2026-05-25T21:38:08+00:00

I am getting the following error when i try to read a XML file

  • 0

I am getting the following error when i try to read a XML file from the memory and into an object. Seems like problem with getting the Context. Can anyone tell me whats wrong with my code?

Code:

public class WifiScanning extends Service {

private static final String TAG = "WifiScanning";
private Timer timer;
public int refreshRate;

public WifiScanning() {
    super();
    Configuration config = new Configuration();
    SAXParserFactory spf = SAXParserFactory.newInstance(); 
    SAXParser sp;
    XMLReader xr = null; 
    DataHandler dataHandler = null;
    try {
        sp = spf.newSAXParser();
        xr = sp.getXMLReader();
        dataHandler = new DataHandler(); 
        xr.setContentHandler(dataHandler); 


        xr.parse(new InputSource(this.openFileInput("config.xml")));
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

    config = dataHandler.getConfig();
    refreshRate = Integer.parseInt(config.getMapRefreshRate());
    // TODO Auto-generated constructor stub
}

private TimerTask updateTask = new TimerTask() {
    @Override
    public void run() {
        Log.i(TAG, "Timer task doing work");
    }
};

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG, "Service creating");

    timer = new Timer("TweetCollectorTimer");
    Log.i(TAG, "Refresh Rate: "+ String.valueOf(refreshRate));
    timer.schedule(updateTask, 0, 3000L);

}

@Override
public void onDestroy() {
    super.onDestroy();
    Log.i(TAG, "Service destroying");

    if (timer != null){
        timer.cancel();
        timer.purge();
        timer = null;
    }
}

public void onStop() {
    Log.i(TAG, "Service destroying");
    if (timer != null){
        timer.cancel();
        timer.purge();
        timer = null;
    }
}
}

LogCat:

10-01 11:08:49.804: ERROR/AndroidRuntime(21514): java.lang.RuntimeException: Unable to instantiate service android.wps.WifiScanning: java.lang.NullPointerException
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2764)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at android.app.ActivityThread.access$3200(ActivityThread.java:119)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1917)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at android.os.Looper.loop(Looper.java:123)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at android.app.ActivityThread.main(ActivityThread.java:4363)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at java.lang.reflect.Method.invokeNative(Native Method)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at java.lang.reflect.Method.invoke(Method.java:521)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at dalvik.system.NativeStart.main(Native Method)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514): Caused by: java.lang.NullPointerException
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at android.content.ContextWrapper.openFileInput(ContextWrapper.java:152)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at android.wps.WifiScanning.<init>(WifiScanning.java:52)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at java.lang.Class.newInstanceImpl(Native Method)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at java.lang.Class.newInstance(Class.java:1479)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2761)
10-01 11:08:49.804: ERROR/AndroidRuntime(21514):     ... 10 more
  • 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-25T21:38:09+00:00Added an answer on May 25, 2026 at 9:38 pm

    You should do this not in the constructor, but only between (inclusive) onCreate() and onDestroy().

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

Sidebar

Related Questions

I'm getting the following error when I try to use the JSTL XML taglib:
I am getting a 401 unauthorized error when I try to read an XML
I getting the following error when I try to connect to my server app
I'm getting the following error when I try to Serialize an HttpWebRequest Type 'System.Net.KnownHttpVerb'
I'm getting the following error when I try to install one of my ClickOnce
I am getting the following error when i try to use a blue tooth
I'm getting the following error when I try to run a simple Java JDBC
I am getting the following error when I try to access bins private member
I'm getting the following error when I try to startup my application on google
I'm getting the following error when I try to install mod_wsgi ./configure checking for

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.