0

So, yeah...its that error. Given the code, I don't know what I'm missing or not doing to make it work:

RegionQuery(allPointsDbscan, p.ClusterPoint, epsilon, deltaX, deltaY, out neighborPts);

if (neighborPts != null)
{
  if (neighborPts.Length < minPts)
      p.ClusterId = (int)ClusterIds.Noise;
  else
  {
      clusterId++;
      ExpandCluster(allPointsDbscan, p, neighborPts, clusterId, epsilon, minPts, deltaX, deltaX);
  }
}



private void RegionQuery(DbscanPoint[] allPoints, DatasetItem point, double epsilon, double delta_X, double delta_Y, out DbscanPoint[] neighborPts)
{
   if (delta_X < 0.1499 && delta_Y < 0.0899)
   {
       neighborPts = allPoints.Where(x => _metricFunc(point, x.ClusterPoint) <= epsilon).ToArray(); 
   }
   else
       neighborPts = null;
}

I don't understand why its throwing me that exception, because I check to see if neighborPts is NULL or not before I do anything with it; but it appears that I can't even do that. Why is this?

MethodMan
  • 18,625
  • 6
  • 34
  • 52
John
  • 447
  • 2
  • 8
  • 20
  • 4
    On which line does this exception get thrown? – adv12 Dec 21 '15 at 19:46
  • This is something you should figure out by debugging into your program. That will tell you where the exception is thrown and what was null – Kevin Dec 21 '15 at 22:36
  • Obviously, `neighborPts` is `NULL`. But why is it throwing an exception when I'm not even doing anything with it until I've checked if it is `NULL`? – John Dec 22 '15 at 01:04
  • @adv12 The issue is not that it's being thrown...its the fact that it shouldn't be thrown...I'm not even using `neightborPts` until after I've checked if it is `NULL`. So it is most likely being thrown in the second `if` loop in `RegionQuery`. And I don't understand how thats even possible...because if it is `NULL`, it should never enter the loop. – John Dec 22 '15 at 02:02
  • @John, I wasn't asking you to guess. I was asking you what line the debugger breaks on when this exception is thrown. It's not obvious from the code you shared which line that is. The `NullReferenceException` could come from any variable you're using without null-checking, for instance `allPointsDbscan` or `p`. – adv12 Dec 22 '15 at 02:37
  • @adv12 `allPointsDbscan` and `p` are not `NULL`, I've checked. – John Dec 22 '15 at 18:14
  • Great! That helps narrow things down. But what would help the most is knowing on exactly what line the exception gets thrown. – adv12 Dec 22 '15 at 18:16
  • @adv12 The exception gets thrown at the first `if` statement in `RegionQuery`...and I have no idea why...I'm just checking to see if `neighborPts` is `NULL`. – John Dec 22 '15 at 19:11
  • So, at this line? `if (delta_X < 0.1499 && delta_Y < 0.0899)` – adv12 Dec 22 '15 at 19:15
  • @adv12 Sorry, I meant the other `if` statement. The: `if (neighborPts != null)` – John Dec 22 '15 at 20:50
  • OK, like you say, there's nothing in there that could throw that exception. It sounds like your code and the assembly being debugged are not in sync. I've had this sort of thing happen, e.g., when a project got unchecked in the Configuration Manager so it's getting run but not built. I suggest you look for something like that. – adv12 Dec 22 '15 at 20:53
  • @adv12 Checked it...and it is in fact building. – John Dec 22 '15 at 21:50

0 Answers0