Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Getting errors when calling current window - Newbie

Im just starting to use Titanium and running into a problem. First I am on XP 64 bit. Im using example codes find in the api section just to see how it works but I keep getting errors. Below is the code Im trying to run:

var win = Titanium.UI.currentWindow;

var mountainView = Titanium.Map.createAnnotation({
latitude:37.390749,
longitude:-122.081651,
title:"Appcelerator Headquarters",
subtitle:'Mountain View, CA',
pincolor:Titanium.Map.ANNOTATION_RED,
animate:true,
leftButton: '../images/appcelerator_small.png',
myid:1 // CUSTOM ATTRIBUTE THAT IS PASSED INTO EVENT OBJECTS
});
var mapview = Titanium.Map.createView({
mapType: Titanium.Map.STANDARD_TYPE,
region: {latitude:33.74511, longitude:-84.38993,
latitudeDelta:0.01, longitudeDelta:0.01},
animate:true,
regionFit:true,
userLocation:true,
annotations:[mountainView]
});
win.add(mapview);

But I get this error when running it in android emulator:

TypeError: Cannot call method "add" of null. I get that all the time if I try to use the add function for the current window. I event tried using Titanium.UI.currentWindow.add(mapview) but still same error.

— asked October 5th 2010 by Robert Bartlett
  • android
  • map
  • typeerror
0 Comments

6 Answers

  • Accepted Answer

    Yes you have to do win.open(); on the newly created window.

    — answered October 7th 2010 by John McKnight
    permalink
    0 Comments
  • Did you create a window? There aren't any by default.

    — answered October 5th 2010 by Don Thorp
    permalink
    0 Comments
  • Did you create a window? There aren't any by default.

    — answered October 5th 2010 by Don Thorp
    permalink
    0 Comments
  • No I didnt, I didnt think a window needed to be created. I even used a tutorial that had a working example and it gave me the same type of error:

    var win = Titanium.UI.currentWindow;
    win.backgroundColor = '#13386c';
    win.barColor = '#13386c';

    This one gives me type error null for backgroundColor. So in order to use the current window you have to create it? Because I have seen a lot of example code that only used the currentWindow at the very top of the line of the code before all other code. I didnt see the part about it creating a window first.

    — answered October 5th 2010 by Robert Bartlett
    permalink
    0 Comments
  • In the example that you had, it had been opened from elsewhere and provided Ti.UI.currentWindow.

    — answered October 7th 2010 by Don Thorp
    permalink
    0 Comments
  • Yeah I think you are correct. But just adding it isnt enough, do I have to also use win.open() to get it to display?

    — answered October 7th 2010 by Robert Bartlett
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.