Im getting an error: Uncaught TypeError: Cannot read property '1' of null Source: X.push( check [ 1 ]);
what is the problem?
wspolrzedne.value = text typed in textArea like that: "2.4 5 1 67 15 67"
So maybe the problem is becouse titanium do not safe that string with \n as new line?
var coordinates = wspolrzedne.value.split( "\n" );
var X = [];
var Y = [];
for( var i = 0; i < coordinates.length; ++i ) {
var check = coordinates[ i ].match( /^([0-9]+.[0-9]*) ([0-9]+.[0-9]*)$/ );
if( check == false) {
var zlewspolrzedne = Ti.UI.createAlertDialog({
title: "Niew?a?ciwe wspó?rz?dne: " + coordinates[ i ],
buttonNames: ['Popraw'],
cancel: 0
});
zlewspolrzedne.show();
}
X.push( check[ 0 ] );
Y.push( check[ 1 ] );
}
This is because textArea
doesn't care about linebreaks
, its just a simple whitespace. So the solution is to split by '' and then concat each two of them (or feed every pair directly to the check array and check their content on the fly).
Edit:
Ok, so the problem is this line:
var check = coordinates[ i ].match( /^([0-9]+.[0-9]*) ([0-9]+. [0-9]*)$/ )
It assigns only one value instead of two.