Please i really need help on it. Thanks
Hamza Fetuga wrote:Hey guys! While I was trying to solve this problem, www.codechef.com/problems/SUMTRIAN but I keep getting nullpointerexception error and I'm certain it has to do with getting the elements present in an array in a method different from the one it was created in. I'm pretty sure my algorithm is right. Here's my code
In main you are not creating, initializing, and filling the instance variable, you are creating a new method local variable which has the same name (and so hides the instance variable). So later, when you try to use the instance variable you get nulls because it hasn't been initialized or filled.
You're not initializing the member variable b (declared in line 9) of that object anywhere, so it is null.
Note: the b that you declare and initialize in line 20 is a local member variable, which has nothing to do with the member variable of the sumtrial object.
In line 33 you call str.getstore(0,0);, then you get to line 61, where a NullPointerException happens because the member variable b of the sumtrial object is null.
Error: not a statement
Error: ; expected
Error: ] expected