Page 1 of 1

Uncaught TypeError: Cannot read property '0' of null

Posted: Wed Jan 07, 2015 5:50 pm
by Don7312172

When I first test this I get the uncaught exception error. If I refresh it goes away and the graph loads great. How do I go about fixing this?

var L1 = JSON.parse(sessionStorage.getItem("daily_pts"));
var x1 = JSON.parse(sessionStorage.getItem("daily_goal"));
var line1 = [];
var ticks = [];

for (var i=0; i < 7; i++ )
{
line1.push(L1); // console says there error is on this line
ticks.push(x1);
}

$.jqplot('myplot', [line1],
{
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
rendererOptions: {fillToZero: false}
},
title:'Daily Points',
axes:{
xaxis:{
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
},
yaxis:{min:0, max:100}}
});


Uncaught TypeError: Cannot read property '0' of null

Posted: Wed Jan 07, 2015 8:53 pm
by Don7312172

Now Chrome Console says the error is on the final line of the page html

Any ideas where to start?


Uncaught TypeError: Cannot read property '0' of null

Posted: Thu Jan 08, 2015 4:20 am
by Yurii Orishchuk

HI Don,

I tried to access L1 object that's seems to be "null".

Here is code where you get this object:

pre

var L1 = JSON&#46;parse(sessionStorage&#46;getItem("daily_pts"));

/pre

So "daily_pts" has no JSON correct data.

You can modify this code to workaround this problem:

pre

var L1 = JSON&#46;parse(sessionStorage&#46;getItem("daily_pts"));
if(!L1)
L1 = [];

/pre

Regards.


Uncaught TypeError: Cannot read property '0' of null

Posted: Thu Jan 08, 2015 3:44 pm
by Don7312172

After putting that in - I still see that error and the graph shows when testing.

I've shared my project if that helps. I only have one app on it. Main Reports This Week

I don't understand why if I refresh it works? sigh


Uncaught TypeError: Cannot read property '0' of null

Posted: Thu Jan 08, 2015 4:15 pm
by Don7312172

It doesn't error every time as well. But when I download to my phone - it is every time.


Uncaught TypeError: Cannot read property '0' of null

Posted: Thu Jan 08, 2015 11:15 pm
by Don7312172

Ok, took it back to the basics and started. It's working now. :)