Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3465] Android: XML Cannot call method parseString if only defined inside an event listener

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionFixed
Resolution Date2011-07-27T09:22:59.000+0000
Affected Version/sRelease 1.6.2
Fix Version/sSprint 2011-30, Release 1.8.0
ComponentsAndroid
Labelsreported-1.6.1, tooling, xml
ReporterJon Alter
AssigneeNatalie Huynh
Created2011-04-15T03:45:31.000+0000
Updated2011-08-26T16:15:19.000+0000

Description

On Android, If parseString is only defined inside an event listener then you will get an error.

Note

This only happens until you define it outside of the eventListener once. After that it will work fine in that application even if it is inside an event listener. In order to reproduce this error you MUST create a new application.

Step 1: Create a NEW application
Step 2: Paste the example below into app.js
Step 3: Run the app
Step 4: Click 'Find Foo'
Step 5: Notice Runtime Error (picture of error attached)

var xmlString = '<items><foo>FOO</foo><bar>BAR</bar></items>';

var window = Ti.UI.createWindow({
    backgroundColor: 'green'
});

var button = Ti.UI.createButton({
    title: 'Find Foo',
    height: 60,
    width: 100,
  top: 40
});
button.addEventListener('click', function(e){
    var xml = Titanium.XML.parseString(xmlString);
  var element = xml.getElementsByTagName("foo");
  Ti.API.info( element.item(0).text );
});

window.add(button);
window.open();

Tested on

TiSDK 1.6.1, Android SDK 2.1

Attachments

FileDateSize
error.jpg2011-04-15T03:45:31.000+000081012

Comments

  1. Bill Dawson 2011-07-25

    pull request ready https://github.com/appcelerator/titanium_mobile/pull/276
  2. Bill Dawson 2011-07-25

    XML module was not being included in build because: a) It has an all upper case name, which means it was being treated as a constant rather than a module. b) No other module outside of Network had a dependency on it, and only Yahoo has a dependency on Network, so it was easy for XML to be avoided given (a) above.
  3. Don Thorp 2011-07-27

    Reviewed and tested.
  4. Natalie Huynh 2011-08-26

    Tested with 1.8.0.v20110819142548 on Motorola Xoom 3.2 Droid 1 2.2.2

JSON Source