A new problem has shown up with my app, which appears to affect only certain
devices. I don't have a lot of information about the failure, but my current
best guess is it appears to be failing to read or parse an internal XML
resource.
I read one of several XML files from res/xml and use that to dynamically
initialize a java class / data structure (ie: coordinates of bitmaps based
on a skin definition -- not device, region, or resolution dependent).
There's nothing device-specific there, so it seems like if that had a
problem, it wouldn't be specific to any one device. And that method has
been working fine for a long time, across many resolutions, languages, and
devices from 1.5 to 2.2+ -- but I recently got a vague report that suggests
it's not working with a Sanyo / Kyocera Zio (on Cricket) running 1.6 -- and
possibly also on some tablet of unknown make and model (but not a Galaxy
Tab). The failure mode suggests that it is able to find the XML from the
resources, but the data is not making it from the XML to the java class.
If I had access to a device (or a patient tester with one) I could probably
solve this with detailed logging, but at the moment, I'm stuck. Does anyone
have any ideas or similar experience?
-----------
Here is the code for the class which takes a Resource and ID and a Java
object and assigns any properties with the same name in the XML to the Java
object. (apologies if this method is outdated / bad practice / etc. I wrote
it when I was just starting on Android and java is not my native tongue.).
package lars.FlightPanel;
import org.xmlpull.v1.XmlPullParser;
import android.content.res.Resources;
import java.lang.reflect.*;
import java.lang.Class;
public class XMLClassReader
{
private static final String TAG = "XMLClassReader";
private String lead_tag;
private boolean verbose = false;
XMLClassReader () { } ;
public Object Read (int resourceID, Object target,Resources R)
{
XmlPullParser xpp = R.getXml(resourceID);
return Read (xpp,target);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public Object Read (XmlPullParser xpp, Object target)
{
lead_tag = "XMLParser: ";
try
{
int eventType = xpp.getEventType();
while (eventType!=XmlPullParser.END_DOCUMENT)
{
if (eventType==XmlPullParser.START_TAG)
ReadTag(xpp, target.getClass(),target);
eventType = xpp.next();
}
Field fld = target.getClass().getDeclaredField("XML_Loaded");
// FlightPanel.LocalLog(TAG, lead_tag+"field is " + fld + " in " + target);
if (fld!=null)
fld.setInt (target, Integer.parseInt("1"));
FlightPanel.LocalLog(TAG, lead_tag+" done loading all.");
}
catch (Exception e)
{
e.printStackTrace();
FlightPanel.LocalLog(TAG, lead_tag+" error " + e.toString());
}
return target;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
private void ReadTag (XmlPullParser xpp, Class cls,Object target)
{
String orig_lead_tag = lead_tag;
lead_tag+="\t";
try
{
String thistag = xpp.getName();
if (verbose ) FlightPanel.LocalLog(TAG, lead_tag+" starting parsing of XML
tag " + thistag);
if (verbose) FlightPanel.LocalLog(TAG, lead_tag+" - into class " +
cls.getName() + " containing :");
Field[] flds = cls.getDeclaredFields();
for (int x=0;x<flds.length;x++)
if (verbose) FlightPanel.LocalLog(TAG, lead_tag+" -- " + flds[x].getName()
+ " \t " + flds[x]);
int index;
// read the primitives out as attributes
for (index = 0; index < xpp.getAttributeCount();index++)
{
String attributeName = xpp.getAttributeName(index);
try
{
Field fld = cls.getDeclaredField(attributeName);
String value = xpp.getAttributeValue(index);
if (verbose) FlightPanel.LocalLog(TAG, lead_tag+" = matched XML attribute "
+ attributeName + "\t assigning value "+ value);
String typname = fld.getType().getName();
if (verbose) FlightPanel.LocalLog(TAG, lead_tag+" == to field \t" + fld + "
of type " + fld.getType() + " \t " + typname);
if (verbose) FlightPanel.LocalLog(TAG, lead_tag+" == on object \t" + target
+ " \t " + target.getClass());
if (typname.equals("int"))
fld.setInt (target, Integer.parseInt(value));
else if (typname.equals("float"))
fld.setFloat (target, Float.parseFloat(value));
else if (typname.equals("boolean"))
fld.setBoolean (target, Boolean.parseBoolean(value));
else if (typname.equals("double"))
fld.setDouble (target, Double.parseDouble(value));
else if (typname.equals("byte"))
fld.setByte (target, Byte.parseByte(value));
else if (typname.equals("short"))
fld.setShort (target, Short.parseShort(value));
else if (typname.equals("long"))
fld.setLong (target, Long.parseLong(value));
// todo: add strings and arrays
//
}
catch (Exception e)
{
FlightPanel.LocalLog(TAG, lead_tag+" error no field matching XML attribute "
+ attributeName);
FlightPanel.LocalLog(TAG, lead_tag+" error " + e.toString());
}
}
// read any subclasses
xpp.next();
int eventType = xpp.getEventType();
while (eventType!=XmlPullParser.END_DOCUMENT &&
eventType!=XmlPullParser.END_TAG)
{
if (xpp.getEventType()==XmlPullParser.START_TAG)
{
String tagname = xpp.getName ();
if (verbose) FlightPanel.LocalLog(TAG, lead_tag+" >> diving into complex XML
tag " + tagname);
try
{
Field fld = cls.getDeclaredField(tagname);
ReadTag(xpp, fld.getType(), fld.get(target));
}
catch (Exception e)
{
FlightPanel.LocalLog(TAG, lead_tag+" error no field matching XML tag " +
tagname);
FlightPanel.LocalLog(TAG, lead_tag+" error " + e.toString());
}
}
eventType = xpp.next();
}
if (verbose) FlightPanel.LocalLog(TAG, lead_tag+" done with " + thistag);
}
catch (Exception e)
{
e.printStackTrace();
FlightPanel.LocalLog(TAG, lead_tag+" error " + e.toString());
}
lead_tag = orig_lead_tag;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
--------------------
and the system & build report from the one offending device's profile is:
zio cricket
DRC92
cricket/zio/msm7627_kb60/zio:1.6/DRC92/Android.1.002CR.1:user/ota-rel-keys,release-keys
TAGS:release-keys
1281453694000
user DRC92 Android-BS7 cmd_public
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en