Don7312172
Posts: 0
Joined: Tue Jan 06, 2015 3:41 pm

Uncaught TypeError: Cannot read property '0' of null

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}}
});

Don7312172
Posts: 0
Joined: Tue Jan 06, 2015 3:41 pm

Uncaught TypeError: Cannot read property '0' of null

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

Any ideas where to start?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Uncaught TypeError: Cannot read property '0' of null

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.

Don7312172
Posts: 0
Joined: Tue Jan 06, 2015 3:41 pm

Uncaught TypeError: Cannot read property '0' of null

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

Don7312172
Posts: 0
Joined: Tue Jan 06, 2015 3:41 pm

Uncaught TypeError: Cannot read property '0' of null

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

Don7312172
Posts: 0
Joined: Tue Jan 06, 2015 3:41 pm

Uncaught TypeError: Cannot read property '0' of null

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

Return to “Issues”