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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:04:03+00:00 2026-05-18T00:04:03+00:00

Howdy, I currently have my main activity in Android. It’s called start activity. My

  • 0

Howdy,
I currently have my main activity in Android. It’s called start activity.
My programm is designed so that it loads an XML File from the web, and parses it.

Now in future I want to add also the ability that the program loads the XML file and instead of parsing it every runtime it loads the data from an SQLLite database.

However for that I need to write an interface which capsulates the different functionalities.

In case that the XML needs to be used I wrote me a small class which should cover the XML loading – but I cannot use openFileInput(…) … since that class is not an activity ( does it need to be one?? ).

package com.android.mensa.handledata;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.TreeMap;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import android.app.Activity;

import com.android.mensa.datastructure.LunchPlace;
import com.android.mensa.getData.XMLHandler;
import com.android.mensa.interfaces.Data;

/**
 * This class implements the interface Data
 * and gathers the necessary informations out of the XML File on the actual device.
 */
public class XMLData implements Data{

    @Override
    public void getMenuforDay() {
        // TODO Auto-generated method stub

    }

    public TreeMap<String, LunchPlace> open()
    {
        File test = new File("lunchfile");
        FileInputStream fis;
        TreeMap<String, LunchPlace> places = new TreeMap<String, LunchPlace>();
        try {
            fis = openFileInput("lunchfile");
            XMLHandler xmlhandler = new XMLHandler();
            places  = xmlhandler.parse(fis);            
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return places;
    }
}

I guess my question is pretty basic: does the XMLhandler helper class ( which is supposed to return a TreeMap ) needs to be an activity or how else can I achieve my functionality?

  • 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-18T00:04:04+00:00Added an answer on May 18, 2026 at 12:04 am

    Of the top of my head I can think of two ways to to it:

    The first one is to just use:

    FileInputStream fis = new FileInputStream("lunchfile");
    

    That will however read the file “lunchfile” from the root of the sd-card, I’m not entierly sure if that’s what you want, but if you do it this way I’d recommend changing it “/yourapplication/lunchfile” instead.

    The other is to just pass the activity over to the reader class.

    public TreeMap<String, LunchPlace> open(Context activity)
    {
            [...]
            fis = activity.openFileInput("lunchfile");
            [...]
    }
    

    Hope it helps 🙂

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

Sidebar

Related Questions

Howdy, I have a DataRow pulled out of a DataTable from a DataSet. I
Howdy... here on my local LAN, I have a Windows Server 2k8 box with
Howdy. I'm working on migrating an internal system to Django and have run into
Howdy, I am a programmer that has worked almost exclusively with c++/c#/vbs and am
Howdy, I'm currentyl new to Java and Android but I would like to write
Howdy, I am writing a GRE app on android.i am new in this arena.
Howdy. Consider the following: SQL> DECLARE 2 b1 BOOLEAN; 3 b2 BOOLEAN; 4 FUNCTION
What I want is, I think, relatively simple: > Bin = <<Hello.world.howdy?>>. > split(Bin,
I have an XHTML 1.0 Strict document in which I'm trying to make Shadowbox
Howdy! I'm working on an old project from one of my programming courses and

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.