Hello,
I am trying to make a app in which I need to have Android read a XML
file. I have found some examples on the net which I managed to get to
work if I just create a Java App, but the second when I copy it over to
an Android App it just doesn't work. And what I mean by not working is
that it doesn't appear to be entering to the tags.

Here is my code, I know its a bit messy but I'm just starting out and I
usually get a small area working then clean it up.

First is my main file "MainActivity.java"

package android.Dash8WeightAndBalance;

/*
* Dash 8 Weight and Balance App
* Verison 0.0.1
*
* Build Date : 2012-02-15.00
*
* Copyright 2012
* KCAB Software Productions
*
*/

import android.app.Activity;
import android.view.View;
import android.os.Bundle;

/*
* Only Here For Testing
*/

import android.app.AlertDialog;




public class MainActivity extends Activity
{


/* Create Array To Place Aircraft Data
* 100 Aircraft Double the Size of Current Piedmont Fleet
*/
static public Airplane Aircraft[] = new Airplane[100];


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


/*
* Action Taken When User Presses Accept Button on Welcome Screen
*/

public void accept(View view)
{
Aircraft[1] = new Airplane();
setContentView(R.layout.main);
AircraftDataLoading.LoadAircraft();
AlertDisplay();

}


/*
* This Is here Just to test Differnt Spots Will Delete in Release
Versions
*/
public void AlertDisplay()
{
AlertDialog alertDialog = new
AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Its Working");
alertDialog.setMessage(Aircraft[1].Aircraft_Id);
alertDialog.show();
}


}

Secondly is my Airplane Class file (Airplane.java)

package android.Dash8WeightAndBalance;

import java.math.BigDecimal;

/*
* This Class Records An Airplane and Different Attributes About it
*
* Casey Daniels
* KCAB Software Productions
* Verison : 2012-01-28.00
*/

public class Airplane
{
String Aircraft_Id;
String Aircraft_Type;
BigDecimal Index;
int BOW;

public Airplane ()
{
String Aircraft_Id = "N00000";
String Aircraft_Type = "DHC-8-000";
BigDecimal Index = new BigDecimal("0");
int BOW = 0;
}

public Airplane (String newId, String newType, double newIndex, int
newBow)
{
String Aircaft_Id = newId;
String Aircaft_Type = newType;
BigDecimal Index = new BigDecimal(newIndex);
int BOW = newBow;
}





}


Finally is my DataHandler File "AircraftDataLoading.java"

/*
* Aircraft Loading Functions
*
*
* Build Date : 2012-03-05.00
*
* Copyright 2012
* KCAB Software Productions
*
*/

package android.Dash8WeightAndBalance;


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;

public class AircraftDataLoading extends DefaultHandler {


// ===========================================================
// Fields
// ===========================================================

private static boolean aircrafts = false;
private static boolean aircraft = false;
private static boolean entry = false;
private static boolean aircraft_id = false;
private static boolean aircraft_type = false;
private static boolean index = false;
private static boolean bow = false;


static int RecordNumber = 1;

public static void LoadAircraft()
{




try {



SAXParserFactory factory = SAXParserFactory.newInstance();

SAXParser saxParser = factory.newSAXParser();


DefaultHandler handler = new DefaultHandler()
{




public void startElement(String uri, String
localName,String qName,
Attributes attributes) throws SAXException
{

if (qName.equalsIgnoreCase("aircrafts"))
{
MainActivity.Aircraft[1].Aircraft_Id = "BobBob";
aircrafts = true;
}

if (qName.equalsIgnoreCase("aircraft"))
{

aircraft = true;
}


if (qName.equalsIgnoreCase("entry"))
{

entry = true;
}

if (qName.equalsIgnoreCase("id"))
{

MainActivity.Aircraft[1].Aircraft_Id = "BobBob";
aircraft_id = true;

}

if (qName.equalsIgnoreCase("type")) {

aircraft_type = true;
}

if (qName.equalsIgnoreCase("index")) {
index = true;
}

if (qName.equalsIgnoreCase("bow")) {
bow = true;
}

}

public void endElement(String uri, String localName,
String qName) throws SAXException
{
if (qName.equalsIgnoreCase("aircrafts"))
{
aircrafts = false;
}

if (qName.equalsIgnoreCase("aircraft"))
{
aircraft = false;
}

}



public void characters(char ch[], int start, int length) throws
SAXException {




if (entry)
{
MainActivity.Aircraft[1].Aircraft_Id = new String(ch, start, length);
entry = false;
}



if (aircraft_id)
{
MainActivity.Aircraft[1].Aircraft_Id = new String(ch, start, length);
aircraft_id = false;
}

if (aircraft_type) {
System.out.println("Aircraft Type : " + new String(ch, start, length));
aircraft_type = false;
}

if (index) {
System.out.println("Starting Index : " + new String(ch, start, length));
index = false;
}

if (bow) {
System.out.println("Basic Operating Weight : " + new String(ch,
start, length));
bow = false;
}

}

};


saxParser.parse("res/xml/aircraft.xml", handler);

} catch (Exception e) {
e.printStackTrace();
}

}

}

Thank you for your help.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-platform@googlegroups.com.
To unsubscribe from this group, send email to android-platform+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupandroid-platform @
categoriesandroid
postedMar 6, '12 at 1:47p
activeMar 6, '12 at 1:47p
posts1
users1
websiteandroid.com

1 user in discussion

Casey Daniels: 1 post

People

Translate

site design / logo © 2022 Grokbase