Recently I learned about ArcEngine development and encountered a strange exception. The code is not accessible. After checking the code several times, the Code seems to me that there is no logic error, but there is no draw line. During the step-by-step operation, the process jumps out of the green code. Check again and again, add try {} catch {} in the green code, and finally throw an exception. Exception: "The object reference is not set to the instance of the object ". Check found that the check box for the exception settings is not selected (as shown below) (I do not know why it is not selected by default), VS does not automatically throw an exception, the process automatically jumps out when an unsolved problem occurs. After an exception is thrown, the error can be easily modified. Change the statement in the error field to ipolympus line pDrawPolyline = new ESRI. ArcGIS. Geometry. PolylineClass ();
Select all the check boxes that cause exceptions.
Bool DrawPolylineOrNot = false; // specifies whether to draw a line.
Int DrawPolylineClickCount; // specifies the number of points to be drawn when drawing a line.
Ipolympus line pDrawPolyline = null; // Error
Private void axmapcontrolpoliconmousedown (object sender, ESRI. ArcGIS. Controls. IMapControlEvents2_OnMouseDownEvent e)
{
If (e. button = 1)
{
IPoint pPoint = new PointClass ();
PPoint. PutCoords (e. mapX, e. mapY );
// Curve used to draw a Section
If (DrawPolylineOrNot)
{
// Click it for the first time and set the start point
If (DrawPolylineClickCount = 0)
{
PDrawPolyline. FromPoint = pPoint;
DrawPolylineClickCount ++;
}
Else if (DrawPolylineClickCount = 1)
{
PDrawPolyline. ToPoint = pPoint;
DrawPolylineClickCount = 0;
DrawPolylineOrNot = false;
AxMapControl1.DrawShape (pDrawPolyline );
AxMapControl1.Refresh ();
}
}
}
}