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.
6 Answers
-
Accepted Answer
Yes you have to do win.open(); on the newly created window.
-
Did you create a window? There aren't any by default.
-
Did you create a window? There aren't any by default.
-
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.
-
In the example that you had, it had been opened from elsewhere and provided Ti.UI.currentWindow.
-
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?